rails-migrations

Add a reference column migration in Rails 4

只谈情不闲聊 提交于 2019-11-26 21:08:08
A user has many uploads. I want to add a column to the uploads table that references the user . What should the migration look like? Here is what I have. I'm not sure if I should use (1) :user_id, :int or (2) :user, :references . I'm not even sure if (2) works. Just trying to do this the "rails" way. class AddUserToUploads < ActiveRecord::Migration def change add_column :uploads, :user_id, :integer end end Relevant question except for Rails 3. Rails 3 migrations: Adding reference column? Kirti Thorat Rails 4.x When you already have users and uploads tables and wish to add a new relationship

Add a reference column migration in Rails 4

假装没事ソ 提交于 2019-11-26 07:50:47
问题 A user has many uploads. I want to add a column to the uploads table that references the user . What should the migration look like? Here is what I have. I\'m not sure if I should use (1) :user_id, :int or (2) :user, :references . I\'m not even sure if (2) works. Just trying to do this the \"rails\" way. class AddUserToUploads < ActiveRecord::Migration def change add_column :uploads, :user_id, :integer end end Relevant question except for Rails 3. Rails 3 migrations: Adding reference column?