我在使用表更新的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());
}
我做错了什么?谢谢!
您必须打电话
yii migration/update urban_tourdate
第二次(不是create
)。