我在命令行上运行了php artisan migrate:rollback
,因此迁移删除了数据库中的所有表。
仅创建了一个迁移,但已使用的数据库中有其他表。
laravel documentation说:
To drop an existing table, you may use the
drop
ordropIfExists
methods.
迁移代码中的函数 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 文档)错误?
最佳答案
关于php - Schema::dropIfExists() 在迁移时删除了数据库中的所有表:回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56367482/