title: SQLite3 error in rails SQLite3::SQLException: no such column
body: <p>I am making a rails app where a user can post courses and also subscribe to courses.My model files are:<br>
  <strong>user.rb:</strong>  </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :courses, dependent: :destroy
    has_many :coursejoins, dependent: :destroy
    has_many :learnables, through: :coursejoins, class_name: "Course"
    has_many :comments, dependent: :destroy
    ...
  end
  </code></pre>
  
  <p><strong>course.rb:</strong>  </p>
  
  <pre><code>class Course &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :category
    has_many :coursejoins, dependent: :destroy
    has_many :students, through: :coursejoins, class_name: "User"
    has_many :documents, dependent: :destroy
    has_many :comments, dependent: :destroy
    ...
  end
  </code></pre>
  
  <p><strong>coursejoin.rb:</strong>  </p>
  
  <pre><code>class Coursejoin &lt; ActiveRecord::Base
    belongs_to :learnable, :class_name =&gt; "Course"
    belongs_to :student, :class_name =&gt; "User"
  end
  </code></pre>
  
  <p><strong>20160219171527_create_coursejoins.rb</strong></p>
  
  <pre><code>class CreateCoursejoins &lt; ActiveRecord::Migration
    def change
      create_table :coursejoins do |t|
        t.boolean :accepted
        t.timestamps
      end
    end
  end
  </code></pre>
  
  <p><strong>20160219174937_add_student_id_to_coursejoins.rb</strong></p>
  
  <pre><code>class AddStudentIdToCoursejoins &lt; ActiveRecord::Migration
    def change
      add_column :coursejoins, :student_id, :integer
    end
  end
  </code></pre>
  
  <p><strong>20160219224309_add_learnable_id_to_coursejoins.rb</strong></p>
  
  <pre><code>class AddLearnableIdToCoursejoins &lt; ActiveRecord::Migration
    def change
      add_column :coursejoins, :learnable_id, :integer
   end
  </code></pre>
  
  <p>end</p>
  
  <p>The coursejoin model is like a relation between a course and a user.<br>
  When I try to do @course.students, i get error:  </p>
  
  <pre><code>SELECT "users".* FROM "users" INNER JOIN "coursejoins" ON "users"."id" = "coursejoins"."student_id" WHERE "coursejoins"."course_id" = ?  [[nil, 1]]
  ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: coursejoins.course_id: SELECT "users".* FROM "users" INNER JOIN "coursejoins" ON "users"."id" = "coursejoins"."student_id" WHERE "coursejoins"."course_id" = ?
  </code></pre>
  
  <p>I don't know SQL much so I am not able to decipher the error.<br>
  I looked at questions with similar error but none seemed related.<br>
  I have been stuck with this for two days.<br>
  How do I fix this?  </p>