Rails migration to reference a User, how to add this foreign key? -
i have 2 models, user , post.
i want post model have user in i.e. add user_id in posts table.
what migration like? or manually like:
add_column :posts, :user_id:integer
yep, manually. it'll this:
class adduseridtoposts < activerecord::migration def self.up add_column :posts, :user_id, :integer end def self.down remove_column :posts, :user_id end end
Comments
Post a Comment