0

I am writing migrations script in cakephp 3 using Phinx. I need to add a column with primary key while updating the table(using update() command) using migrations. But when I run the script, it created the column but does not include the primary key.

  $table->addColumn('book_id', 'integer', [
     'default' => null,
     'limit' => 11,
     'null' => true
  ])->addPrimaryKey('book_id');
  $table->update();

Thanks

Dhruv
  • 27
  • 5

2 Answers2

1

Per the Docs:

Dealing with primary key can only be done on table creation operations. This is due to limitations for some database servers the plugin supports.

Andy Hoffner
  • 3,267
  • 2
  • 21
  • 22
1
public function change(): void
{
    $this->table('table_name')
    ->changePrimaryKey(['column1', 'column2'])
    ->save();
}
prophp
  • 91
  • 2
  • 4