-1

I face this issue when display one-to-many relationship in laravel 4

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 
'subject_start.teacher_subject_id' in 'where clause'
(SQL: select * from `subject_start` where `subject_start`.`teacher_subject_id` = 1)

but i have reviewed the migration file and database table ,i seen this column called teach_sub_id. why laravel throw this QueryException.

Any Suggestions ?

Muhammad Atallah
  • 976
  • 2
  • 12
  • 34
  • If its called `teach_sub_id ` and you use `teacher_subject_id ` in your query... Then you are trying to access a none-existant column, they differ. – Jite Apr 27 '15 at 06:14

2 Answers2

1

I am very confident that actually the teacher_subject_id does not exist in your table subject_start. You can doublecheck it if you open your mysql console and type in

desc subject_start;

This will display you all the column in this table that exist.

If it is your intention to use different column then you can change your Eloquent relationship like this

$this->hasMany("TeacherSubject", "custom_key_column")
Margus Pala
  • 8,433
  • 8
  • 42
  • 52
  • 1
    me too Margus Pala I am very confident also , i checked it from mysql console before. also i checked it from laravel Schema $columns = Schema::getColumnListing('subject_start'); teacher_subject_id not exist but when display one-to-many relationship between subject_start and teacher_subject laravel throw the above Exception – Muhammad Atallah Apr 27 '15 at 06:56
  • 1
    Awesome , thanks sir Margus Pala , now i can get the relationship well ,sorry i can't vote your Answer i have no point enough to do that . but till now i don't understand why that error is occurred if you have any idea please tell me – Muhammad Atallah Apr 27 '15 at 07:15
1

copy the query and run directly on DB. you will see if your query is correct or not.

Sumit Kumar
  • 1,855
  • 19
  • 19