我有以下迁移:
class MoveInventoryItems < ActiveRecord::Migration
def up
schraenke = ('F'..'J')
List::Inventory::Item.find_each do |item|
if schraenke.include?(item.location[0])
item.location[0] = item.location[0].next.next
item.save!
end
end
end
end
我正在尝试更改特定项目的变量。当我尝试在保存后输出该项目时,它看起来是正确的。当我运行迁移时它没有显示任何错误。但显然它并没有真正得到更新,因为当我运行服务器时旧值仍然显示。
所以我的问题是:迁移怎么可能不更新数据?
实际上,up是类级别的方法,你可以用下面的代码替换上面的代码,它会更新记录。
class MoveInventoryItems < ActiveRecord::Migration
def self.up
schraenke = ('F'..'J')
List::Inventory::Item.find_each do |item|
if schraenke.include?(item.location[0])
item.location[0] = item.location[0].next.next
item.save!
end
end
end
def self.down
#put reverse code of above, it will execute when you rollback migration
end
end
我是一名优秀的程序员,十分优秀!