Rails Migrating Foreign Keys -


i have discovered relationship between 2 of tables wrong , make necessary changes - involves dropping foreign key on accommodations table , adding foreign key on users table.

i have created migration file using:

rails g migration foreignkeyadjustment 

and added new migration file:

class foreignkeyadjustment < activerecord::migration   def self.up     remove_column :accommodations, :user_id     add_column :users, :accommodation_id, :integer   end end 

i ran migration using:

bundle exec rake db:migrate 

and used console check column names in each table , changes have not taken effect!

rails console 

and

user.column_names 

what missing?

p.s. major issue if deleted models , database migration files , generated new models terminal? wouldn't take me long , no important data consider.

have established active record associations? allow map records 1 table another. otherwise column name arbitrary name in table.

did add foreign key attribute model? creates attribute existing model through in attr accessible

these can of potential problems

guide on associations http://guides.rubyonrails.org/association_basics.html

i edit title of question "migrating foreign keys" other people can find answers similar questions.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -