Recently I got a question about rails3.1's migration.Here is the one of the migration file code.
def change
create_table :books do |t|
t.string :title
t.decimal :price
end
end
Now I need to add a foreign key, let's say comment_id, I used to create another migration and use add_column method in it to get it done.
But since we are in rail3.1,so I thought there might be a new way to do it.so I alter the code
def change
create_table :books do |t|
t.string :title
t.decimal :price
t.references :comment
end
end
OK,now I run rake db:migrate and nothin开发者_JAVA百科g happens. Any idea?
did you run rake db:rollback
before running rake db:migrate
? You need to roll back the migration before reapplying it with the changes.
精彩评论