开发者

database migration in rails3.1

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜