1
votes

I had created a table in a Phinx migration using

$table = $this->table('verification', ['id' => false, 'primary_key' => ['validation_id']]);
$table->addColumn('validation_id','string',['limit' => 15, 'null' => false])
        ->addColumn('status','string', ['null' => true])
    >create();

Now in a separate migration I want to alter the table and set that id value to true and make that id as primary key (default behaviour). And make validation_id as a unique index.

I know how to do it by dropping the table first and creating new table. But I don't want to drop the table, just alter it. How to alter table to add back the auto increment default id column?

1

1 Answers

0
votes

An easy way to change the structure in a database is to use a db client such as sequalpro, mysql workbench, sqlyog, etc.

When you make changes, run the command:

bin/cake bake migration_diff NameOfTheMigrations

This command will create a migration file for you with all the changes you have made in the db client.

Remark:

If you do not have previous migration files, you must first run the command:

bin/cake migrations dump

Read more:

https://book.cakephp.org/migrations/3/en/index.html#generating-a-diff-between-two-database-states