Laravel migration shows column doesn’t exist for existing columns

DB::statement("
      CREATE VIEW course_market_view AS
      (
        SELECT 
        users.id,
        users.name,
        course.id,
        course.courseUniqueName,
        skills.id,
        skills.skill,
        subjects.id,
        subjects.subject
         FROM users 
          LEFT JOIN course ON course.userId=users.id
          LEFT JOIN skills ON skills.userId=users.id
          LEFT JOIN subjects ON subjects.userId = users.id         
      )
    ");

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

IlluminateDatabaseQueryException 
SQLSTATE[42703]: Undefined column: 7 ERROR:  column course.userid does not exist at character 294
HINT:  Perhaps you meant to reference the column "course.userId".

Course table migration file

Schema::create('course', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('userId')->unsigned();
                $table->foreign('userId')->references('id')->on('users');
                $table->string('courseDisplayName');
                $table->string('courseUniqueName')->unique();
                $table->string('courseAddedBy');
                $table->dateTime('createdOn');
                $table->dateTime('lastUpdated');
                $table->softDeletes();        
            });

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.

Source: Laravel

Leave a Reply