"Migrate reset" 代码出错时不工作

"Migrate reset" not working when there is an error in code

在基本 Laravel 应用程序中,在用户 class 中我添加了:

use SoftDeletes;

应用程序不再运行,因为 MySql 数据库的用户 table 中没有 'deleted_at' 列。我试图通过删除所有 table 并重新创建它们(或删除所有 table)来添加此列:

artisan migrate:refresh --seed

artisan migrate:reset

artisan migrate:fresh

在所有情况下我都会得到一个错误:

Illuminate\Database\QueryException : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.deleted_at' in 'where clause' (SQL: select exists(select * from users where email = user@gmail.com and users.deleted_at is null) as exists)

我不明白。如果我要恢复迁移,artisan 应该只对我的用户 class 调用 down() 方法,即:

public function down()
{
    Schema::dropIfExists('users');
}

如果找不到列,删除 table 应该不会失败。

P.S。我正在使用 docker-compose 到 运行 php、mysql、artisan、composer、nginx 和 nodejs - 如果这很重要的话。

原来给出的答案不正确,因为问题也有些不正确,在聊天中讨论后,我们发现作者也在 AppServiceProvider 中进行了迁移,这阻止了通过 CLI 进行实际迁移。

您可以阅读the chat here。从 AppServiceProvider 中删除 artisan 调用解决了这个问题

您是否也在迁移中添加了软删除?

public function up()
{
    Schema::table('users', function(Blueprint $table)
    {
        $table->softDeletes();
        ...
    });
}