【问题标题】:yii2 migration generates createTable instead of addColumnyii2 迁移生成 createTable 而不是 addColumn
【发布时间】:2020-01-22 12:32:09
【问题描述】:

我在表更新时使用 bizley/yii2-migration-creator 扩展进行自动创建迁移时遇到问题。最初,它可以按预期使用新表:

<?php

use yii\db\Migration;

class m200122_110631_update_table_yii_urban_tourdate extends Migration
{
    public function up()
    {
        $this->createTable('{{%urban_tourdate}}', [
            'id' => $this->primaryKey(),
            'name' => $this->string()->notNull(),
            'time' => $this->dateTime(),
            'duration' => $this->integer(),
            'tour_id' => $this->integer(),
            'tourguide_id' => $this->integer(),
            'tourcourse_id' => $this->integer(),
            'start_station_id' => $this->integer(),
            'stop_station_id' => $this->integer(),
            'status' => $this->integer(3)->notNull(),
            'created_by' => $this->integer(),
            'updated_by' => $this->integer(),
            'created_at' => $this->integer(),
            'updated_at' => $this->integer(),
        ]);

    }

    public function down()
    {
        $this->dropTable('{{%urban_tourdate}}');
    }
}

然后直接在数据库中添加一列并创建另一个迁移后,我得到一个如上的 createTable 语句(带有添加的列),这导致应用迁移时出错(表已存在)。

我的期望是只得到这样的 addColumn 语句:

public function up()
{
    $this->addColumn('urban_tourdate', 'position', $this->integer());
}

我做错了什么?谢谢!

【问题讨论】:

    标签: yii2 migration


    【解决方案1】:

    你必须打电话

    yii migration/update urban_tourdate
    

    第二次(不是create)。

    【讨论】:

      猜你喜欢
      • 2012-09-12
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 2022-06-18
      相关资源
      最近更新 更多