Ruby on Rails迁移时的一些注意事项
把schema.rb保存在版本管控之下。
使用rakedb:scheme:load取代rakedb:migrate来初始化空的数据库。
使用rakedb:test:prepare来更新测试数据库的schema。
避免在表里设置缺省数据。使用模型层来取代。
defamount self[:amount]or0 end
然而self[:attr_name]的使用被视为相当常见的,你也可以考虑使用更罗嗦的(争议地可读性更高的)read_attribute来取代:
defamount read_attribute(:amount)or0 end
当编写建设性的迁移时(加入表或栏位),使用Rails3.1的新方式来迁移-使用change方法取代up与down方法。
#过去的方式 classAddNameToPerson<ActiveRecord::Migration defup add_column:persons,:name,:string end defdown remove_column:person,:name end end #新的偏好方式 classAddNameToPerson<ActiveRecord::Migration defchange add_column:persons,:name,:string end end
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短