rails unable to index a foreign key -
rails unable to index a foreign key -
i have 2 separate migration files:
class createleadprofiles < activerecord::migration def alter create_table :lead_profiles |t| t.belongs_to :contact t.timestamps end add_index :lead_profiles, :contact_id end end and:
class createclientprofiles < activerecord::migration def alter create_table :client_profiles |t| t.belongs_to :contact t.belongs_to :leadprofile t.timestamps end add_index :client_profiles, :contact_id add_index :client_profiles, :lead_profile_id end end when running rake db:migrate, next error:
mysql2::error: key column 'lead_profile_id' doesn't exist in table: create index `index_client_profiles_on_lead_profile_id` on `client_profiles` (`lead_profile_id`) client_profile belongs_to lead_profile, , should have lead_profile_id. , want foreign key indexed. doing wrong?
try:
class createclientprofiles < activerecord::migration def alter create_table :client_profiles |t| t.belongs_to :contact t.belongs_to :lead_profile t.timestamps end add_index :client_profiles, :contact_id add_index :client_profiles, :lead_profile_id end end ruby-on-rails
Comments
Post a Comment