把 schema.rb 保存在版本管控之下。
使用 rake db:scheme:load 取代 rake db:migrate 來初始化空的數(shù)據(jù)庫。
使用 rake db:test:prepare 來更新測(cè)試數(shù)據(jù)庫的 schema。
避免在表里設(shè)置缺省數(shù)據(jù)。使用模型層來取代。
def amount self[:amount] or 0 end
然而 self[:attr_name] 的使用被視為相當(dāng)常見的,你也可以考慮使用更羅嗦的(爭(zhēng)議地可讀性更高的) read_attribute 來取代:
def amount read_attribute(:amount) or 0 end
當(dāng)編寫建設(shè)性的遷移時(shí)(加入表或欄位),使用 Rails 3.1 的新方式來遷移 - 使用 change 方法取代 up 與 down 方法。
# 過去的方式 class AddNameToPerson ActiveRecord::Migration def up add_column :persons, :name, :string end def down remove_column :person, :name end end # 新的偏好方式 class AddNameToPerson ActiveRecord::Migration def change add_column :persons, :name, :string end end
標(biāo)簽:張家界 永州 三沙 梧州 荊門 普洱 遼寧 公主嶺
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Ruby on Rails遷移時(shí)的一些注意事項(xiàng)》,本文關(guān)鍵詞 Ruby,Rails,遷移,時(shí),的,一些,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。