1
我的Ruby on Rails移植一個老既包含了實際的遷移也是一個動作修改數據復位遷移:如何處理失敗的,因爲刪除模型/方法
class AddTypeFlagToGroup < ActiveRecord::Migration
def self.up
add_column :groups, :selection_type, :string
Group.reset_column_information
Group.transaction do
Group.all.each do |group|
group.selection_type = group.calculate_selection_type
group.save
end
end
end
def self.down
remove_column :groups, :selection_type
end
end
在此遷移有通常的add_column
和remove_column
遷移語句。但也有一些模型特定的方法調用。
我幾個星期前寫了這個。從那以後,我刪除了我的Group
模型,當我使用:reset
進行完整遷移時出現錯誤。
rake db:migrate:reset
(in /Users/jesper/src/pet_project)
[...]
== AddTypeFlagToGroup: migrating =============================================
-- add_column(:groups, :selection_type, :string)
-> 0.0012s
rake aborted!
An error has occurred, this and all later migrations canceled:
uninitialized constant AddTypeFlagToGroup::Group
問題是,在我的代碼的當前修訂版中,組不存在。我應該如何處理這種「鐵軌方式」?
我在想我可以通過評論Group.xxx
這個東西來修改遷移,但是這是一個明智的選擇嗎?
+1對於arrrrgh。 – 2010-02-04 14:23:05
修改遷移...這就是我認爲我必須做的事情 – 2010-02-04 15:06:42