加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails迁移不能在heroku上运行,Model类报告为未

发布时间:2020-12-17 03:54:11 所属栏目:百科 来源:网络整理
导读:我正在尝试在heroku上运行迁移,我似乎无法找到为什么我的模型类无法识别的问题. 这是我的迁移: class AddTestToGoals ActiveRecord::Migration def change add_column :goals,:test,:integer,default: 0,null: false Goal.reset_column_information Goal.al
我正在尝试在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

谁知道问题是什么?

编辑:错过键入之前,它是无法识别的模型,而不是其中的常量.

半个办公室:

使用这个(我在这里找到: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,null: false
     Goal.reset_column_information
     Goal.all.each { |g| g.update_attribute :test,Goal::PASS }
  end
end

heroku不抱怨不知道什么目标解决了问题的一半.
但是,目标:: PASS无法识别.

解决方法

老问题,但我最近经历过类似的事情,这是由于通过设置禁用自动加载

config.threadsafe!

在我的环境/ staging.rb文件中.
可以通过更换以下内容来修复它

config.threadsafe! unless $rails_rake_task

这应该没问题,因为rake任务不需要线程安全.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读