Rails porting not working on heroku, a model class declared as an uninitialized constant

I am trying to migrate to heroku and I cannot 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 

Launch using

 heroku run rake db:migrate 

and i get this error

 uninitialized constant AddTestToGoals::Goal 

Does anyone know what the problem is?

EDIT: skip typed earlier, this is a model that is not recognized, not a constant in it.

LATELY:

Using this (what 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 does not complain that he does not know what the goal is, which solves half the problem. but then, Goal :: PASS is not recognized.

+4
source share
2 answers

An old question, but I recently experienced something like this, because of which startup was disabled by the installation

 config.threadsafe! 

in my environment / staging.rb file. It can be fixed by replacing it with the following

 config.threadsafe! unless $rails_rake_task 

This should be normal, as there is no need for rake tasks to be thread safe.

+10
source

EDIT:

Change all links to the target with the prefix :: .

 ::Goal.reset_column_information ::Goal.all.each { |g| g.update_attribute :test, ::Goal::PASS } 
0
source

All Articles