【问题标题】:Cannot run any commands on my heroku app (migrate, console, etc)无法在我的 heroku 应用程序上运行任何命令(迁移、控制台等)
【发布时间】:2014-06-19 20:24:23
【问题描述】:

我正在使用 ruby​​ 2.1.1 运行 rails 4.0.4。应用位置:https://github.com/ravjohal/dozmia

例如,当我尝试在 heroku 上运行命令时:

ravjohal$ heroku run rake db:migrate

我收到以下错误:

Running `rake db:migrate` attached to terminal... up, run.2545
rake aborted!
NoMethodError: undefined method `dump_schema_after_migration=' for ActiveRecord::Base:Class
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:166:in `block (3 levels) in <class:Railtie>'...../app/config/environment.rb:5:in `<top (required)>'....

这是heroku日志的一部分:

/app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `dump_schema_after_migration=' for #<Class:0x007fa6e13d76d0> (NoMethodError)
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
2014-03-27T18:30:55.730401+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/engine.rb:464:in `each'
2014-03-27T18:30:55.730191+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
2014-03-27T18:30:55.730191+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:165:in `block (2 levels) in <class:Railtie>'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
2014-03-27T18:30:55.729964+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/railtie.rb:165:in `each'
2014-03-27T18:30:55.730191+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `b
lock in require'
2014-03-27T18:30:55.730191+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/base.rb:22:in `<top (required)>'
2014-03-27T18:30:55.730191+00:00 app[web.1]:    from /app/app/models/playlist.rb:1:in `<top (required)>'

我使用 4.1.0rc1 Rails 部署了我的应用程序(工作正常),然后将 Gemfile 更改为使用 4.0.4。我还将本地开发数据库更改为 pg 而不是 sqllite3。这些是我所做的仅有的两个更改,只有在这些更改之后,问题才会出现在 heroku 上。应用在 localhost 上运行良好。

编辑:我还想补充一点,我在本地更改了应用名称(但不确定这是否重要)。

【问题讨论】:

  • 您在更改 GemFile 后是否运行过 bundle update / install
  • 我怀疑问题是您的 Rails 版本存在错误,从而导致系统出现问题。如果您刚刚更改了对 Rails gem 的 GemFile 引用,您可能希望再次捆绑应用程序
  • 改rails版本没用后我已经捆绑了。

标签: ruby-on-rails ruby heroku


【解决方案1】:

所以在尝试了很多事情之后,并因为没有尝试明显的事情而自责...我从 environment/production.rb 文件中删除了以下行:

config.active_record.dump_schema_after_migration = false

此后它在 heroku 上运行良好。

【讨论】:

  • 这有效(在 Heroku 上的 rails 4.1.9 上),但我不明白为什么删除明确指出“不要做导致错误的事情”的配置选项可以解决问题。
【解决方案2】:

配置 dump_schema_after_migration 在 Rails 4.0.4 中不存在。

您收到错误是因为您最初使用 Rails v4.1.0rc1 部署,后来切换到 v4.0.4。真正发生的是,当您使用 rails 4.1.0rc 生成您的应用程序时,生成器将配置 dump_schema_after_migration 放入您的 config/environments/production.rb 和 Rails 4.1.0rc1 的代码有这个来支持这个配置:

mattr_accessor :dump_schema_after_migration

因此在 v4.1.0rc1 中一切正常。但是当您移回 v4.0.4 时,配置仍然存在于 config/environments/production.rb 中,但 Rails 代码不再知道如何读取此配置。要解决这个问题,要么坚持使用 Rails 4.1.0rc1 代码,要么在 Rails 4.0.4 上运行时从 config/environments/production.rb 中删除配置。

顺便说一句,I added dump_schema_after_migration config to Rails code

【讨论】:

    【解决方案3】:

    我没有答案,但有问题发生的原因

    使用产品 (Rails) 的测试版时,您将获得许多新的(相对未经测试的)功能。这会起作用,但可能会导致早期版本的软件出现问题,因为新版本通常意味着更多功能等

    如果您从 Rails 开始,我建议您从系统中删除 Rails 4.1.0 gem:gem uninstall rails,然后再次安装 Rails 4.0.4 - gem install rails

    这将是 Rails 4.1.0 的一个问题,但我需要进行一些试验

    【讨论】:

    • 当我做rails -v 时,我得到了 Rails 4.0.4。
    • 感谢您的回复!如果您找到解决方案,请告诉我:)
    猜你喜欢
    • 2018-12-28
    • 2012-11-07
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多