0
我正在嘗試解決Oracle無法更改其中包含數據的列的類型。我緩存屬性的正確值,將其設置爲無,重命名列,然後嘗試重新設置屬性:在Rails遷移中的rename_column後保存
class SwitchToForeignKeys < ActiveRecord::Migration
def self.up
registration_countries = {}
Registration.all.each do |r|
if c = Country.find_by_name(r.country)
registration_countries[r.id] = c.id
r.country = nil
r.save
end
end
rename_column :registrations, :country, :country_id
change_column :registrations, :country_id, :integer
Registration.reset_column_information
registration_countries.each do |reg_id, country_id|
r = Registration.find(reg_id)
r.reload
r.country_id = country_id
r.save
end
end
end
在運行遷移我上第二r.save此錯誤:
undefined method `country' for #<Registration:0x7f409698be48>