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
誰が問題が何であるか知っていますか?
EDIT:前にタイプミスしました。認識されないのはモデルであり、その中の定数ではありません。
半分の回避策:
これを使用して(ここで見つけました: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 が何かわからなくても文句を言いません。しかし、その後、Goal::PASS は認識されません。