我正在尝试在 heroku 上运行迁移,但我似乎找不到我的模型类无法识别的问题。
这是我的迁移:
class AddTestToGoals < ActiveRecord::Migration
def change
add_column :goals, :test, :integer, default: 0, null: false
Goal.reset_column_information
Goal.all.each { |g| g.update_attribute :test, Goal::PASS }
end
end
运行它使用
heroku run rake db:migrate
我得到这个错误
uninitialized constant AddTestToGoals::Goal
任何人都知道问题是什么?
编辑:错过之前输入的,它是无法识别的模型,而不是其中的常量。
一半的解决方法:
使用它(我在这里找到:http: //visibletrap.blogspot.co.il/2011/10/heroku-access-railss-model-in-migration.html)
class AddTestToGoals < ActiveRecord::Migration
class Goal < ActiveRecord::Base; end
def change
add_column :goals, :test, :integer, default: 0, null: false
Goal.reset_column_information
Goal.all.each { |g| g.update_attribute :test, Goal::PASS }
end
end
heroku 不会抱怨不知道解决一半问题的目标是什么。但是,Goal::PASS 无法识别。