個人的にわすれるので。

スキーマ作成(※要-fオプション ModelクラスがなくてもSchemaへ反映してくれる)

$ ./Console/cake schema generate -f

Migration作成

$ ./Console/cake Migrations.migration run all -p Migrations

‘schema_migrations’テーブルができる。

変更を加える

テーブル追加など

Migrations実行

$ ./Console/cake Migrations.migration generate -f

実行すると

Cake Migration Shell
---------------------------------------------------------------
Do you want to compare the schema.php file to the database? (y/n)
[y] >

schema.phpと比較するかな? > y

---------------------------------------------------------------
Comparing schema.php to the database...
Do you want to preview the file before generation? (y/n)
[y] >

previewする? y

Please enter the descriptive name of the migration to generate:  
> add_newtable_and_newfields
Generating Migration...

説明する名前つけてなので変更した内容を記述 > add_newtable_and_newfields

Do you want to update the schema.php file? (y/n)
[y] >

スキーマupdate ? yes.

Welcome to CakePHP v2.6.12 Console
---------------------------------------------------------------
App : app
Path: /Users/taka/htdocs/bizmatchocvb/html/businessmatching/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Generating Schema...
Schema file exists.
 [O]verwrite
 [S]napshot
 [Q]uit
Would you like to do? (o/s/q)
[s] > o
Schema file: schema.php generated

上書き? yes で完了。

次回以降は、

$  ./Console/cake Migrations.migration generate -f

で良さそう。

変更内容の適用方法

$ ./Console/cake Migrations.migration run

とすると

Cake Migration Shell
---------------------------------------------------------------
Available migrations:
  [xxxxxxxxxxx] xxxxxxxxxxx_add_newtable_and_newfields
        not applied
---------------------------------------------------------------
Please choose which version you want to migrate to. [q]uit or [c]lean.  
> xxxxxxxxxxx

バージョンを聞いてくる。ので該当の xxxxxxxxxxx を入力して

---------------------------------------------------------------
Running migrations:
  [xxxxxxxxxxx] xxxxxxxxxxx_add_newtable_and_newfields
      > Creating table "bookmarks".
      > Creating table "likes".
      > Creating table "messages".
      > Creating table "notices".
      > Creating table "projects".
      > Adding field "newstype_id" to table "news".

---------------------------------------------------------------
All migrations have completed.

マスター系のテーブルに追加がある場合。

/Config/Migrations/以下のMigrationのプログラムに追記
‘up’した時にどうするかを追記。(‘down’のときも必要)

/**
 * After migration callback
 *
 * @param string $direction Direction of migration process (up or down)
 * @return bool Should process continue
 */
    public function after($direction) {
        if ($direction === 'up') {
            $Group = $this->generateModel('Group');
            $Group->save(array(
                'Group'=>array('name'=>'海外エージェント','key'=>'agent')
            ));
        }
        return true;
    }
}