ここでは簡単によく使うカラムの追加を行うMigrationファイルのテンプレートを貼っていきます。 Migrationファイルのジェネレートは以下で行ってください。
$ cake bake migration AddMyColmunToMyTables
MyColumnやらMyTableは自分の好きに合わせてください
<?php
use Migrations\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;
class AddMyColmunToMyTables extends AbstractMigration
{
public function up()
{
$table = $this->table('my_tables')
->addColumn(
'my_column',
'string', // "integer", "text", "datetime", etc ...
[
'after' => 'exist_column', //ここに指定したカラムのあとに新規に差し込まれる
'default' => null, // デフォルトの値を指定
'limit' => 255, // stringの場合の長さ制約
'null' => true, // NOTNULL制約を行う場合 true
'comment' => 'My Comment', // コメント、あると他の人がなんのカラムかが理解しやすい
]
)->update();
}
public function down()
{
$this->table('my_tables')
->removeColumn('my_column')
->update();
}
}


