【发布时间】:2015-06-06 11:37:55
【问题描述】:
我已经阅读了 Laravel 的文档和其他论坛,但它对我不起作用。我已经成功迁移了一个表,现在我想添加一个字段,将架构更改为“表”,但我得到的只是“无迁移”。
这就是我所做的。
迁移:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product', function(Blueprint $table)
{
$table->text('image');
$table->integer('stock');
$table->integer('amount');
$table->string('color');
$table->string('dimension');
$table->integer('ordered');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('product');
}
}
然后,运行命令php artisan migrate,一切正常。
然后我决定添加新字段,所以我将控制器更改为:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('product', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->text('description');
$table->text('image'); //new
$table->int('active'); //new
$table->integer('stock');
$table->integer('amount');
$table->string('color');
$table->string('dimension');
$table->integer('ordered');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('product');
}
}
然后再次运行php artisan migrate,但我只得到Nothing to migrate。
我还删除了Blueprint,但效果不佳。 migrate:refresh 和 migrate:reset 完成了这项工作,但这不是我想要的,因为它也会删除数据。
【问题讨论】: