在更新 cakephp 时添加带有主键迁移的列

add column with primarykey migrations on update cakephp

我正在使用 Phinx 在 cakephp 3 中编写迁移脚本。 在使用迁移更新 table(使用 update() 命令)时,我需要添加一个带有主键的列。 但是当我 运行 脚本时,它创建了列但不包括主键。

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

谢谢

根据 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.

public function change(): void
{
    $this->table('table_name')
    ->changePrimaryKey(['column1', 'column2'])
    ->save();
}