thinkphp フレームワーク の次のチュートリアル コラムでは、thinkPHP が mitigate を使用してデータベース移行を実装する方法を紹介します。
thinkPHP は、Migrate を使用してデータベース移行を実装します
thinkPHP のデータベース移行ツール: topthink/think-migration 1: topthink/think-migration をインストールします ここで、topthink/think-migration をインストールするときは、thinkPHP のバージョンに注意する必要があることに注意してください。ここでの thinkPHP のバージョンは 5.1 なので、topthink/ のバージョン 2.0 をインストールできます。 think-migration.、バージョン 3.0 はインストールできません。インストールするのに適したバージョンを選択してくださいcomposer require topthink/think-migration=2.0.*
php think
php think migrate:create CreateUser
// create the table $table = $this->table('user', ['id' => 'user_id', 'comment' => '用户表', 'engine' => 'MyISAM', '']); $table->addColumn('user_name', 'string', ['limit' => 15, 'default' => '', 'comment' => '用户名']) ->addColumn('password', 'string', ['limit' => 15, 'default' => '', 'comment' => '密码',]) ->addColumn('status', 'boolean', ['limit' => 1, 'default' => 0, 'comment' => '状态']) ->addIndex(['user_name'], ['unique' => true])//为user_name创建索引并设置唯一(唯一索引) ->addTimestamps()//默认生成create_time和update_time两个字段 ->create();
$this->table('user') ->addColumn('test', 'string', ['limit' => 15, 'default' => '', 'comment' => '测试'])//在user表中增加一个test字段 ->update();
$this->table('user')->drop();
$this->table('user') ->removeColumn('test')//删除user表中的test字段 ->save();
php think migrate:create CreateUser #创建一个迁移类 php think migrate:run #执行迁移 php think migrate:rollback #迁移回滚
以上がthinkPHP が mitigate を使用してデータベース移行を実装する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。