I have such models:
student:
class Student < ActiveRecord::Base
has_many :participations, dependent: :destroy
has_many :subject_item_notes, depe
First, check your sequence of migrations. It seems that you are trying to create a reference before creating the table subject_items
itself.
You should first create students table then your subject_items table then add the reference. Or alternatively add the reference columns yourself when creating the tables which is all what add_reference does.
Also, You have two relations from Student
to SubjectItem
.
has_many :subject_items, dependent: :destroy, through: :participations
has_many :subject_items, dependent: :destroy
You need to your first relation in order for ActiveRecord to be able to identify the correct one first for querying then for your migration. Think of the query that will be generated if you called @student.subject_items
for example. Will it go through the first relation or the second one.
Your relations should be ex:
has_many :participation_subject_items, dependent: :destroy, through: :participations
has_many :subject_items, dependent: :destroy