I have a 2 Models, User and Post.
I want the Post model to have a User in it i.e. add a user_id in the Posts table.
What will my migration look like? Or do I just do this manually like:
add_column :posts, :user_id:integer
开发者_开发百科
yep, just do it manually. It'll look like 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
精彩评论