Illuminate\Database\QueryException SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“current_team_id”

Mag*_*min 4 php mysql laravel laravel-jetstream

设置:将数据库从 laravel 7 迁移到 laravel 8、Jetstream with Teams (php artisan jetstream:install惯性 --teams)、inertia.js

\n
Illuminate\\Database\\Connection::runQueryCallback\nvendor/laravel/framework/src/Illuminate/Database/Connection.php:671`\n\nIlluminate\\Database\\QueryException\nSQLSTATE[42S22]: Column not found: 1054 Unknown column \'current_team_id\' in \'field list\' (SQL: update `users` set `current_team_id` = 1, `users`.`updated_at` = 2020-10-08 21:22:00 where `id` = 5)\n
Run Code Online (Sandbox Code Playgroud)\n
/* @throws \\Illuminate\\Database\\QueryException */    \nprotected function runQueryCallback($query, $bindings, Closure $callback)\n{\n    // To execute the statement, we\'ll simply call the callback, which will actually\n    // run the SQL against the PDO connection. Then we can calculate the time it\n    // took to execute and log the query SQL, bindings and time in our memory.\n    try {\n        $result = $callback($query, $bindings);\n    }\n\n    // If an exception occurs when attempting to run a query, we\'ll format the error\n    // message to include the bindings with SQL, which will make this exception a\n    // lot more helpful to the developer instead of just the database\'s errors.\n    catch (Exception $e) {\n        throw new QueryException(\n            $query, $this->prepareBindings($bindings), $e\n        );\n    }\n\n    return $result;\n}\n\n/**\n * Log a query in the connection\'s query log.\n *\n * @param  string  $query\n * @param  array  $bindings\n * @param  float|null  $time\n * @return void\n */\n
Run Code Online (Sandbox Code Playgroud)\n
\n

未找到列您可能忘记运行\n迁移。您可以使用 php artisan migrate 运行迁移。

\n

按下面的按钮将尝试运行您的迁移。

\n
\n

迁移并没有\xc2\xb4解决问题。列应该放在哪里?怎么修?

\n

\n

感谢你们!:)

\n

Sou*_*Boy 10

看来迁移错过了一个领域。通常是由于以错误的顺序运行造成的。您可以运行下面的命令来重新创建数据库,它应该可以解决问题。

警告

此命令将删除您的所有数据,因此仅在开发时运行。

php artisan migrate:fresh

  • 如果这是在本地,则绝对可以解决问题。但是,如果它位于生产服务器上,他将必须手动将该列添加到用户表中。 (2认同)