CakePHP3: Migrations でテーブルを Drop する

備忘録

  • ->save() を忘れない
  • See
    • Phinx - Dropping a Table
      • Note that like other methods in the Table class, drop also needs save() to be called at the end in order to be executed.

サンプル

例: tests テーブを削除

/// 空のマイグレーションファイルを作成
$ ./bin/cake migrations create DropTestsTable
/// config/Migrations/20191024035304_DropTestsTable.php の change メソッドに下記の処理を追加

<?php
use Migrations\AbstractMigration;

class DropTestsTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * More information on this method is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-change-method
     * @return void
     */
    public function change()
    {
        $this->table('tests')
            ->drop()
            ->save(); //save() しないとdropされない
    }
}
/// 実行
$ ./bin/cake migrations migrate