LoginSignup
2
0

More than 5 years have passed since last update.

cakephp2 チーム開発のためのマイグレーション

Last updated at Posted at 2018-01-17

cakephp2のマイグレーションの流れ

1.マイグレーションファイルを新規に作成する
2.マイグレーションを実行する
3.schema.phpをコマンドで上書き更新する (←ここが必要)

マイグレーションファイルを新規に作成する

$ bash app/Console/cake Migrations.migration generate

$ bash app/Console/cake Migrations.migration generate
Cake Migration Shell
---------------------------------------------------------------
Do you want to compare the schema.php file to the database? (y/n)
[y] > n
Do you want to compare the database to the schema.php file? (y/n)
[y] > n
Do you want to preview the file before generation? (y/n)
[y] > n
Please enter the descriptive name of the migration to generate:
>

Migration name () is invalid. It must only contain alphanumeric characters and start with a letter.
Please enter the descriptive name of the migration to generate:
> test
Generating Migration...

Done.
$

Config/Migratinon/1513308893_test.php

最後にファイル名を聞かれるのでいったんtestにしたが
大事なのは数字です。日付が自動で生成されます。

ファイル名や中身を変える

適当に変更してください。

マイグレーションを実行する

$ bash app/Console/cake Migrations.migration run all

schema.phpをコマンドで上書き更新する

$ bash app/Console/cake schema generate -f

→『o』を選択する

$ bash app/Console/cake schema generate -f

Welcome to Mega Solar Power Monitoring System
---------------------------------------------------------------
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
$

新規に作成したマイグレーションファイルと、
更新したschema.phpをコミットして終了です。

Reference

参考
https://qiita.com/KNaito/items/de47d123405bea5a2efe

2
0
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
2
0