Generating Your First Migration
The first step to adding migrations to an existing database is to import the database's structure into a format the migrations can work with. Namely a migration file. To create the _first_ migration file run the following command:
cake migration generate This will give us the following prompt:
Cake Migration Shell
---------------------------------------------------------------
Please enter the descriptive name of the migration to generate:
>
Enter in 001 initial migration as the name for the migration and hit return. Since this is the first time you ran this command you will then get the following prompt:
Do you wanna generate a dump from current database? (y/n)
[y] >
Answer y to this question as we want to import the existing database schema into our migrations. This will scan the model paths and import schema for each model found. Once you have been returned to the prompt check app/config/migrations/ for the newly created files. You should see two files in the migrations directory. The first 001_initial_migration is the actual migration containing the table definitions for your database. The second is map.php, this is a special Map file which keeps track of the order of migrations are to be run in. At this point you now have the current database imported into the migration system and can do further schema changes in a regular fashion.
Then the following output will be give as result:
Generating dump from current database...
Generating Migration...
Mapping Migrations...
Done.
Note: If you want import all tables regardless if it has a model or not you can use -f (force) parameter while running the command:
cake migration generate -f