CakePHP3(Phinx)のMigrationファイルの記述備忘録
bakeでmigrationファイルの作成
$ bin/cake bake migration MigrationName
カラムの追加
users
テーブルにphoto
というカラムを文字型255文字で追加。
public function change()
{
$table = $this->table('users');
$table->addColumn('photo', 'string', ['limit' => 255])
->update();
}
カラムの制約を変更
nullを許容する。
public function change()
{
$table = $this->table('users');
$table->changeColumn('photo', 'string', ['limit' => 255, 'null' => true])
->update();
}