Ode*_*ded 4 migration ruby-on-rails heroku
我正在尝试在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
Run Code Online (Sandbox Code Playgroud)
使用它运行它
heroku run rake db:migrate
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
uninitialized constant AddTestToGoals::Goal
Run Code Online (Sandbox Code Playgroud)
谁知道问题是什么?
编辑:错过键入之前,它是无法识别的模型,而不是其中的常量.
半个办公室:
使用此(我在这里找到: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
Run Code Online (Sandbox Code Playgroud)
heroku不抱怨不知道什么目标解决了问题的一半.但是,目标:: PASS无法识别.
Sim*_*dal 10
老问题,但我最近经历过类似的事情,这是由于通过设置禁用自动加载
config.threadsafe!
Run Code Online (Sandbox Code Playgroud)
在我的环境/ staging.rb文件中.可以通过更换以下内容来修复它
config.threadsafe! unless $rails_rake_task
Run Code Online (Sandbox Code Playgroud)
这应该没问题,因为rake任务不需要线程安全.
| 归档时间: |
|
| 查看次数: |
877 次 |
| 最近记录: |