Skip to content
Advertisement

Laravel migration shows column doesn’t exist for existing columns

JavaScript

I’ve written the above code in the up method of my migration but when running migrate command, it shows –

JavaScript

Course table migration file

JavaScript

I don’t have any idea why this error occurs because i’ve the userId column in my ‘course` table migration. Any help is much appreciated.

EDIT

Output:

JavaScript

View Query

JavaScript

Model

JavaScript

Controller

JavaScript

Advertisement

Answer

Problem A. “column course.userid does not exist”

With

HINT: Perhaps you meant to reference the column “course.userId”

This was solved by using " for field names with uppercased letters.

JavaScript
  • Single quotes for query
  • double quotes around fields names

Problem B. id-fields

it’s not fetching the data from the columns course.id,skills.id & subjects.id

The problem is that 4 fields are named as id.

To fix it – use field aliases:

JavaScript

This way id will became 4 different fields as it’s in reality:

  • user_id – from table users
  • course_id – from course
  • skill_id – from skills
  • subject_id – from `subjects

Change application code accordingly to field renames.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement