doumibi6899 2019-07-27 04:56
浏览 984
已采纳

PDOException::(“SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'问题'”)

After php artisan db:seed I am getting error:

1   PDOException::("SQLSTATE[42S22]: Column not found: 1054 Unknown column 'question' in 'field list'")
      F:\Projects\phpealtimeApp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452

2   PDO::prepare("insert into `replies` (`body`, `question`, `user_id`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)")"

Here is my Github repo: https://github.com/hevzy86/realtimeApp

  • 写回答

2条回答 默认 最新

  • duanlu1950 2019-07-27 05:29
    关注

    In your replies table migration, you create a field called question_id:

    Schema::create('replies', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->text('body');
                $table->integer('question_id')->unsigned(); // <--- here
    
                $table->timestamps();
            });
    

    However, in your migration, which depends on the Factory you have created for replies, you are setting the field to question:

    $factory->define(Reply::class, function (Faker $faker) {
        return [
            'body' => $faker->text,
            'question' => function(){  // <--- here
                return Question::all()->random();
            },
            'user_id' => function(){
                return \App\User::all()->random();
            },
        ];
    

    Change the question in your factory to call an id (figure out which questions are already in the db, and just pull a random id) and name it correctly according to the field (question_id)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误