Table column mismatch in Laravel eloquent

Published 7 months ago by afoysal

I am getting error like below

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'skills.applicant_skill_id' in 'where clause' (SQL: select * fromskillswhereskills.applicant_skill_idin ())

But I have no applicant_skill_id column in skills table. I have a id column in skills table. What can I do in this regard ?

Thanks.

Best Answer (As Selected By afoysal)
Cronix

You'd override them in your applicant_skill() relationship. See the docs where it shows you for each type of relationship (hasOne, hasMany, etc): https://laravel.com/docs/5.5/eloquent-relationships

I'd urge you to stick to conventions though. It's a lot more straightforward and less confusing, especially when you come back and look at your code a year from now.

bashy
bashy
7 months ago (1,002,020 XP)

I'm guessing you used Laravel's default values for your relationship or something?

If you're linking applicants to skills then Laravel would expect (by default) to see certain columns to relate them.

afoysal

@bashy thanks. Tes, you are right. Laravel expect see certain column name but my names are different. What to do ? Thanks.

bashy
bashy
7 months ago (1,002,020 XP)

You can override them by passing extra params to the relation you've defined or create the expected columns and keep to the convention of Laravel.

afoysal

How can I override them ? I am using this code $applicants = Applicant::with('applicant_skill.skills')->paginate();. Thanks.

Cronix
Cronix
7 months ago (732,290 XP)

You'd override them in your applicant_skill() relationship. See the docs where it shows you for each type of relationship (hasOne, hasMany, etc): https://laravel.com/docs/5.5/eloquent-relationships

I'd urge you to stick to conventions though. It's a lot more straightforward and less confusing, especially when you come back and look at your code a year from now.

bashy
bashy
7 months ago (1,002,020 XP)

That reply is the exact same as mine :(

Please sign in or create an account to participate in this conversation.