I'm trying to run a migration on heroku and I can't seem to find the problem why my model class is not recognized.
This is my migration:
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
Running it using
heroku run rake db:migrate
and I get this error
uninitialized constant AddTestToGoals::Goal
Anyone knows what the problem is?
EDIT: miss typed before, it's the model which is not recognized, not the constant in it.
HALF WORKAROUND:
Using this (which I found here: 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 doesn't complain about not knowing what Goal is which solves half of the problem. but then, Goal::PASS is not recognized.