dolor3sh4ze
dolor3sh4ze

Reputation: 1165

Column not found: 1054 Unknown column 'id' in 'where clause' Laravel 5.6

I try to delete a row from my db but I can't access to it since I've not an ID colmun and 2 primary keys as you can see below:

Trying to delete:

$follow = Follow::where('follower', Auth::id())->where('follows', $id)->get()->first();
$follow->delete();

My migration:

Schema::create('followed_by', function (Blueprint $table) {
    $table->integer('follower')->unsigned();
    $table->integer('follows')->unsigned();
    $table->foreign('follower')->references('id')->on('users');
    $table->foreign('follows')->references('id')->on('users');
    $table->primary(['follower', 'follows']);
 });

So I don't know how can I access to it since I don't know which primary key I suppose to define in my model (I've tried twice)

Upvotes: 0

Views: 1237

Answers (1)

Emil Georgiev
Emil Georgiev

Reputation: 528

I would strongly suggest still having an ID and use it as a primary key. You can set multiple primary key in the model but it's not always working as expected. If you wish you could try to add protected $primaryKey = ['follower', 'follows']; but I think you will have some other issues in the future even if this works.

Upvotes: 2

Related Questions