LoginSignup
0
2

More than 5 years have passed since last update.

CakePHP3のMigration記述備忘録

Posted at

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();
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2