Tuesday, December 28, 2021

[FIXED] add column with primarykey migrations on update cakephp

Issue

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


Solution

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.



Answered By - ahoffner

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.