SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `songs` where `id` = 5 limit 1)

前端 未结 5 1862

I am trying to get specific data from the database by using column SongID when a user clicks a link but I am getting this error:

SQLSTATE[42

5条回答
  •  庸人自扰
    2021-02-02 08:18

    I am running laravel 5.8 and i experienced the same problem. The solution that worked for me is as follows :

    1. I used bigIncrements('id') to define my primary key.
    2. I used unsignedBigInteger('user_id') to define the foreign referenced key.

          Schema::create('generals', function (Blueprint $table) {
              $table->bigIncrements('id');
              $table->string('general_name');
              $table->string('status');
              $table->timestamps();
          });
      
      
          Schema::create('categories', function (Blueprint $table) {
              $table->bigIncrements('id');
              $table->unsignedBigInteger('general_id');
              $table->foreign('general_id')->references('id')->on('generals');
              $table->string('category_name');
              $table->string('status');
              $table->timestamps();
          });
      

    I hope this helps out.

提交回复
热议问题