首页 > 解决方案 > Phinx 表已经存在?想增加 1 个额外的桌子

问题描述

我对 phinx 很陌生,我进行了许多迁移并运行了创建应该具有的表的迁移。

但是我做了一个新的迁移来添加一个额外的表,现在如果我运行migrate -c phinx.php它会尝试重新添加已经存在的表。

有没有办法只添加一个迁移?因为我不想删除我的数据库并再次插入它们

这是我要添加的迁移

<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CustomerCompanyTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
      $table = $this->table('customer_company');
      $table
            ->addColumn('customer_id', 'integer', ['limit' => 11, 'null' => true])
            ->addColumn('company_id', 'integer', ['limit' => 11, 'null' => true])
            ->create();
    }
}

标签: phpphinx

解决方案


推荐阅读