Wednesday 15 April 2015

Add a foreign key to an existing rails model -



Add a foreign key to an existing rails model -

i have rails 4 app.

i have 2 tables, 1 'scope' , 1 'data'. info belongs scope. forgot add together foreign key when set info , i'm trying write migration add together 1 now.

i have created alter table, migration i've written isn't working.

i can't follow rails guides illustration because isn't consistent experience i'm having in setup (not sure why).

the migration have is:

class addfkeytodata < activerecord::migration def alter add_foreign_key :data, :scopes end end

please can help me identify problem.

thank you

rollback migration by:

rake db:rollback

then go migration , edit add_foreign....

to:

add_column :data, :scope_id, :integer

should work!

ruby-on-rails

No comments:

Post a Comment