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.
Old question, but I recently experienced something like it which was due to autoloading being disabled by setting
config.threadsafe!
in my environments/staging.rb file. It can be fixed by replacing it with the following
config.threadsafe! unless $rails_rake_task
This should be OK as there is no need for rake tasks to be threadsafe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With