我刚刚学会了如何使用迁移.我成功创建了一个包含此架构的表:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
}
不幸的是我错过了列路径,所以我试图添加它.首先,我通过laravel documentation告知myselfe,了解如何添加新列.
从文档:
The table method on the Schema facade may be used to update existing
tables.
我的尝试:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('units', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
Schema::table('units', function (Blueprint $table) {
$table->string('path');
});
}
但是,在执行PHP artisan migrate之后,我无法迁移.
我究竟做错了什么?
解决方法:
您需要首先回滚迁移,这会破坏包含所有数据的上次迁移表:
PHP artisan migrate:rollback
然后再次运行PHP artisan migrate命令.这是应用程序开发过程中的最佳选择.
如果你不想出于某种原因(应用程序是实时等),但只想添加一列,然后创建一个新的迁移并添加此代码:
public function up()
{
Schema::table('units', function (Blueprint $table) {
$table->string('path');
});
}
并运行以下命令:
composer dumpauto
PHP artisan migrate