【发布时间】:2018-07-26 05:04:25
【问题描述】:
在一个 Laravel 项目中,我在创建表迁移文件中编写了以下 up() :
public function up()
{
Schema::create('employees', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
并运行迁移命令:
php artisan migrate
并且表创建成功,然后我创建了另一个迁移文件来修改我的表添加一个新列并编写了以下 up():
public function up()
{
Schema::table('employees', function (Blueprint $table) {
$table->string('name');
});
}
正如预期的那样,该列已成功添加。
我的问题是当我修改最后一个文件以添加新列时
public function up()
{
Schema::table('employees', function (Blueprint $table) {
$table->string('name');
$table->string('address');
});
}
并运行:
php artisan migrate
该命令给了我没有要迁移的东西,所以我应该为每个修改创建一个新的迁移文件还是应该运行其中一个命令
php artisan migrate:rollback
或
php artisan migrate:refresh
得到我的修改?但在最后的命令中,数据会丢失,我不希望这种情况发生。
【问题讨论】: