2007-11-23
db:migrate时,Table already exist 的解决办法
关键字: rails ruby migrate
在运行rake db:migrate时,有时会发现 rake abort 的错误,rake说某个表已经存在,因此这个migrate的工作它干不了。这个表确实是已经存在的,那么如何让rake跳过这个表,或是强制覆写这个表呢?有一处需要修改:
原migrate文件:
修改后的migrate文件:
看出来了吗,在create_table的参数中,加上 :force => true即可。
原migrate文件:
ruby 代码
- class CreateProducts < ActiveRecord::Migration
- def self.up
- create_table :products do |t|
- t.column :title, :string
- t.column :description, :text
- t.column :image_url, :string
- end
- end
- def self.down
- drop_table :products
- end
- end
修改后的migrate文件:
ruby 代码
- class CreateProducts < ActiveRecord::Migration
- def self.up
- create_table :products, :force => true do |t|
- t.column :title, :string
- t.column :description, :text
- t.column :image_url, :string
- end
- end
- def self.down
- drop_table :products
- end
- end
看出来了吗,在create_table的参数中,加上 :force => true即可。
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 40708 次
- 性别:

- 来自: 武汉

- 详细资料
搜索本博客
我的相册
Range表达式图示说明
共 8 张
共 8 张
最新评论
-
如果有两处分页……
谢谢了!一上google马上找到了!
-- by llleelay -
db:migrate时,Table alre ...
学习了,我以前也经常出现这种问题,只知道不行了用version重新来。看来要好好 ...
-- by mirway -
搞定dojo引起的ie6“无法 ...
hax 写道有啥不同啊? 计算绝对地址的时候结果不同。 另外,base已经是xh ...
-- by jindw -
搞定dojo引起的ie6“无法 ...
有啥不同啊?
-- by hax -
搞定dojo引起的ie6“无法 ...
确实。一旦有<base href="<%=basePath%>"> ...
-- by jindw






评论排行榜