【问题标题】:add column with primarykey migrations on update cakephp在更新 cakephp 上添加具有主键迁移的列
【发布时间】:2021-04-08 16:53:39
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: cakephp migration cakephp-3.0 phinx


    【解决方案1】:

    the Docs:

    只能在建表时处理主键 操作。这是由于某些数据库服务器的限制 插件支持。

    【讨论】:

      【解决方案2】:
      public function change(): void
      {
          $this->table('table_name')
          ->changePrimaryKey(['column1', 'column2'])
          ->save();
      }
      

      【讨论】:

        猜你喜欢
        • 2016-09-21
        • 2017-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-03
        • 1970-01-01
        • 2019-06-16
        相关资源
        最近更新 更多