php think 
migrate
migrate:create Create a new migration ///创建
migrate:rollback Rollback the last or to a specific migration //回滚
migrate:run Migrate the database //执行
migrate:status Show migration status //状态查看
optimize
optimize:autoload Optimizes PSR0 and PSR4 packages to be loaded wit
h classmaps too, good for production.//朗读优化PSR0和PSR4软件包,也可以通过类映射加载,有利于生产。
optimize:config Build config and common file cache.//构建公共配置文件缓存
optimize:route Build route cache.//构建路由缓存
optimize:schema Build database schema cache. //构建数据库构建缓存
seed
seed:create Create a new database seeder //创建新的数据填充器
seed:run Run database seeders //运行填充器
#创建迁移类,首字母必须为大写
php think migrate:create Users

参考: http://docs.phinx.org/en/latest/index.html

注意:

  1. Please be aware that when a change method exists, Phinx will automatically ignore the up and down methods. If you need to use these methods it is recommended to create a separate migration file.
    当change方法存在时,将会自动忽略up /down 方法,如果想要生效需要单独创建文件;
  2. When creating or updating tables inside a change() method you must use the Table create()and update() methods. Phinx cannot automatically determine whether a save() call is creating a new table or modifying an existing one.
    change()方法内创建或更新表时,必须使用表create()update()方法。Phinx无法自动确定save()是创建新表还是修改现有表。
  3. Phinx 只能撤销 createTable / renameTable / addColumn / renameColumn / addIndex / addForeignKey 命令;

—— Phinx支持在数据库表上创建外键约束。让我们在示例表中添加一个外键:

<?php

use Phinx\Migration\AbstractMigration;

class MyNewMigration extends AbstractMigration
{
/**
* Migrate Up.
*/
public function up()
{
$table = $this->table('tags');
$table->addColumn('tag_name', 'string')
->save(); $refTable = $this->table('tag_relationships');
$refTable->addColumn('tag_id', 'integer', ['null' => true])
->addForeignKey('tag_id', 'tags', 'id', ['delete'=> 'SET_NULL', 'update'=> 'NO_ACTION'])
->save(); } /**
* Migrate Down.
*/
public function down()
{ }
}

  

——有效列类型

In addition, the MySQL adapter supports enumset and blob column types.

In addition, the Postgres adapter supports jsonjsonbuuidcidrinet and macaddr column types (PostgreSQL 9.3 and above).

以下是有效的列选项:对于任何列类型:

For decimal columns:

For enum and set columns:

For integer and biginteger columns:

For timestamp columns:

朗读您可以使用addTimestamps()方法将created_at和updated_at时间戳添加到表中。此方法还允许您提供替代名称。可选的第三个参数允许您更改要添加的列的时区选项。此外,您可以使用addTimestampsWithTimezone()方法,该方法是addTimestamps()的别名,它始终将第三个参数设置为true(请参阅下面的示例)。

<?php

use Phinx\Migration\AbstractMigration;

class MyNewMigration extends AbstractMigration
{
/**
* Migrate Change.
*/
public function change()
{
// Use defaults (without timezones)
$table = $this->table('users')->addTimestamps()->create();
// Use defaults (with timezones)
$table = $this->table('users')->addTimestampsWithTimezone()->create(); // Override the 'created_at' column name with 'recorded_at'.
$table = $this->table('books')->addTimestamps('recorded_at')->create(); // Override the 'updated_at' column name with 'amended_at', preserving timezones.
// The two lines below do the same, the second one is simply cleaner.
$table = $this->table('books')->addTimestamps(null, 'amended_at', true)->create();
$table = $this->table('users')->addTimestampsWithTimezone(null, 'amended_at')->create();
}
}

  

For boolean columns:

For string and text columns:

For foreign key definitions:

Limit Option and MySQL

When using the MySQL adapter, additional hinting of database column type can be made for integertext and blob columns. Using limit with one the following options will modify the column type accordingly:

Limit Column Type
BLOB_TINY TINYBLOB
BLOB_REGULAR BLOB
BLOB_MEDIUM MEDIUMBLOB
BLOB_LONG LONGBLOB
TEXT_TINY TINYTEXT
TEXT_REGULAR TEXT
TEXT_MEDIUM MEDIUMTEXT
TEXT_LONG LONGTEXT
INT_TINY TINYINT
INT_SMALL SMALLINT
INT_MEDIUM MEDIUMINT
INT_REGULAR INT
INT_BIG BIGINT
use Phinx\Db\Adapter\MysqlAdapter;

//...

$table = $this->table('cart_items');
$table->addColumn('user_id', 'integer')
->addColumn('product_id', 'integer', ['limit' => MysqlAdapter::INT_BIG])
->addColumn('subtype_id', 'integer', ['limit' => MysqlAdapter::INT_SMALL])
->addColumn('quantity', 'integer', ['limit' => MysqlAdapter::INT_TINY])
->create();

  

Get a column list
$columns = $this->table('users')->getColumns();

Get a column by name
$column = $this->table('users')->getColumn('email');

Checking whether a column exists   检查列是否存在

<?php

use Phinx\Migration\AbstractMigration;

class MyNewMigration extends AbstractMigration
{
/**
* Change Method.
*/
public function change()
{
$table = $this->table('user');
$column = $table->hasColumn('username'); if ($column) {
// do something
} }
}

  

更多查看:http://docs.phinx.org/en/latest/migrations.html#working-with-columns

thinkphp 迁移数据库 -Phinx 简单说明文档的更多相关文章

  1. sdk 简单说明文档草稿。

    SDK初始化: HighApi为SDK核心类,请客户端持有其唯一单例对API进行调用. HighApi构造器函数 HighApi(Context appContext, final String ap ...

  2. oracle存储过程--导出数据库表的说明文档

    Oracle查询表的名字和comments select a.table_name,b.comments from user_tables a,ALL_TAB_COMMENTS b where a.t ...

  3. 利用DBExportDoc V1.0 For MySQL自动生成数据库表结构文档

    对于DBA或开发来说,如何规范化你的数据库表结构文档是灰常之重要的一件事情.但是当你的库,你的表排山倒海滴多的时候,你就会很头疼了. 推荐一款工具DBExportDoc V1.0 For MySQL( ...

  4. 【工具篇】利用DBExportDoc V1.0 For MySQL自动生成数据库表结构文档

    对于DBA或开发来说,如何规范化你的数据库表结构文档是灰常之重要的一件事情.但是当你的库,你的表排山倒海滴多的时候,你就会很头疼了. 推荐一款工具DBExportDoc V1.0 For MySQL( ...

  5. 原创SQlServer数据库生成简单的说明文档小工具(附源码)

    这是一款简单的数据库文档生成工具,主要实现了SQlServer生成说明文档的小工具,目前不够完善,主要可以把数据库的表以及表的详细字段信息,导出到 Word中,可以方便开发人员了解数据库的信息或写技术 ...

  6. 原创SQlServer数据库生成简单的说明文档包含(存储过程、视图、数据库批量备份)小工具(附源码)

    这是一款简单的数据库文档生成工具,主要实现了SQlServer生成说明文档的小工具,目前不够完善,主要可以把数据库的表以及表的详细字段信息,导出到 Word中,可以方便开发人员了解数据库的信息或写技术 ...

  7. Net 通用权限管理系统源码 带数据库设计文档,部署说明文档

    Net 通用权限管理系统源码 带数据库设计文档,部署说明文档 包括数据库设计文档部署安装文档源码数据库文件 下载地址:http://www.mallhd.com/archives/1389

  8. 卡牌手游源码《暗黑世界V1.3》数据库表说明文档!!!

    原地址:http://blog.csdn.net/uxqclm/article/details/11970761 欢迎来到9秒:www.9miao.com 由于看到论坛中有人询问需求<暗黑世界V ...

  9. 《暗黑世界V1.3》数据库表说明文档

    <暗黑世界V1.3>数据库表说明文档 (下载地址:http://www.9miao.com/forum.php?mod=viewthread&tid=38821&highl ...

随机推荐

  1. 杭电ACM2018--母牛的故事

    母牛的故事 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  2. 筛选出和该元素相交的元素之BoundingBoxIntersectsFilter

    //假设元素为ee BoundingBoxXYZ box = ee.get_BoundingBox(doc.ActiveView); //创建outline,通过boundingboxintersec ...

  3. 在java中如何实现字符串的反转

    如 "abcdt" 反转之后是 "tdcba" 思路1: 运用递归的方法进行反转 假设反转方法为 reverseString(String str)1)当字符串 ...

  4. 2019/1.7 js面向对象笔记

    面向对象 1.构造函数里的属性怎么看?看this,谁前面有this谁就是属性. num不是属性,是私有作用域下的私有变量. 2.如何查找面向对象中的this 1.构造函数的this指向实例对象 2.如 ...

  5. Ajax的面试题

    一.什么事Ajax?为什么要用Ajax?(谈谈对Ajax的认识) 什么是Ajax: Ajax是“Asynchronous JavaScript and XML”的缩写.他是指一种创建交互式网页应用的网 ...

  6. 工具资源系列之给虚拟机装个centos

    前文我们已经讲解了如何在 mac 系统上安装虚拟机软件,这节我们接着讲解如何利用虚拟机安装 centos 镜像. 安装镜像的大致步骤基本相同,只不过是配置项略显不同而已,如果需要安装其他系统镜像,请参 ...

  7. 我的第一个python web开发框架(39)——后台接口权限访问控制处理

    前面的菜单.部门.职位与管理员管理功能完成后,接下来要处理的是将它们关联起来,根据职位管理中选定的权限控制菜单显示以及页面数据的访问和操作. 那么要怎么改造呢?我们可以通过用户的操作步骤来一步步进行处 ...

  8. Centos7安装搜狗输入法.

    系统默认安装输入法管理器的是 ibus. 而搜狗使用 fcitx 1.以我们先要安装 fcitx和必要的软件包 yum -y install fcitx* yum -y install libQtWe ...

  9. Linux:Day20(上) openssh和CA

    ssh:secure shell protocol,22/tcp,安全的远程登陆 OpenSSH:ssh协议的开源实现: dripbear:另一个开源实现: SSH协议版本 v1:基于CRC-32做M ...

  10. 好程序员web前端分享12个CSS高级技巧汇总

    好程序员web前端分享下面这些CSS高级技巧,一般人我可不告诉他哦. 使用 :not() 在菜单上应用/取消应用边框 给body添加行高 所有一切都垂直居中 逗号分隔的列表 使用负的 nth-chil ...