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
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下