为了账号安全,请及时绑定邮箱和手机立即绑定

在 Illuminate\Database\QueryException 处获取未找到列错误?

在 Illuminate\Database\QueryException 处获取未找到列错误?

PHP
凤凰求蛊 2023-07-01 17:46:04
我正在 Laravel 应用程序中工作,并将users表格与posts表格逐user_id列相关联。我已经user_id在表中有列了posts。但是当我运行php artisan db:seed命令时,出现错误:`SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“user_id”出现以下错误:   Illuminate\Database\QueryException   SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id ' in 'field list' (SQL: insert into `posts` (`user_id `, `title`, `post_image`, `content`, `user_id`, `updated_at`, `created_at`) values (11, Perferendis dolorem eum ex nesciunt., https://lorempixel.com/900/300/?54025, Unde voluptatibus praesentium unde et illum qui quo. Cupiditate pariatur aperiam fugiat perspiciatis. In atque corrupti eius ipsam saepe blanditiis minima., 1, 2020-06-28 08:54:02, 2020-06-28 08:54:02))  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671    667|         // If an exception occurs when attempting to run a query, we'll format the error    668|         // message to include the bindings with SQL, which will make this exception a    669|         // lot more helpful to the developer instead of just the database's errors.    670|         catch (Exception $e) {  > 671|             throw new QueryException(    672|                 $query, $this->prepareBindings($bindings), $e    673|             );    674|         }    675|   • A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.     https://laravel.com/docs/master/migrations#running-migrations      +13 vendor frames   14  database/seeds/DatabaseSeeder.php:21      Illuminate\Database\Eloquent\Relations\HasOneOrMany::save()      +1 vendor frames   16  database/seeds/DatabaseSeeder.php:22      Illuminate\Support\Collection::each()
查看完整描述

1 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

我认为在用户模型的关系函数中,user_id 之后有一个空格。或者你需要找到你在哪里使用了user_id后面的空格。

//img1.sycdn.imooc.com//649ff60a000119a701450036.jpg

查看完整回答
反对 回复 2023-07-01
  • 1 回答
  • 0 关注
  • 94 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信