gpt4 book ai didi

php - Schema::dropIfExists() 在迁移时删除了数据库中的所有表:回滚

转载 作者:行者123 更新时间:2023-11-29 15:57:34 25 4
gpt4 key购买 nike

我在命令行上运行了php artisan migrate:rollback,因此迁移删除了数据库中的所有表。

仅创建了一个迁移,但已使用的数据库中有其他表。

laravel documentation说:

To drop an existing table, you may use the drop or dropIfExists 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 文档)错误?

最佳答案

回滚,回滚上一批的每个迁移。

如果您的所有迁移都在同一批处理中,那么它将回滚所有迁移。因此您的所有表都将从数据库中删除。

enter image description here

关于php - Schema::dropIfExists() 在迁移时删除了数据库中的所有表:回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56367482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com