【发布时间】: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());
}
我做错了什么?谢谢!
【问题讨论】: