【发布时间】:2019-10-15 11:22:46
【问题描述】:
我在命令行上运行了php artisan migrate:rollback,所以迁移删除了数据库中的所有表。
只创建了一个迁移,但在使用的数据库中还有其他表。
laravel documentation 说:
要删除现有表,您可以使用
drop或dropIfExists方法。
迁移代码上的函数down()是默认的,如下所示:
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('image')->unsigned()->nullable();
$table->string('name', 64);
$table->string('slug', 64)->unique();
$table->integer('price')->unsigned();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}
我认为Schema::dropIfExists('products') 在这种情况下不能正常工作,这是一个错误吗?还是我(和 laravel 文档)的错误?
【问题讨论】:
-
还有哪些表?如果您的数据库中有其他表,您应该也为它们进行迁移,并且在这些迁移中,应该有一个调用
Schema::drop()(或dropIfExists())的down()函数。可能需要更多关于此的信息。我不能说我听说过类似的事情发生。 -
是旧版本的现有数据库。我什至还没有创建其他迁移,因为 db 中有超过 100 个表
标签: php mysql laravel laravel-5 migration