无法在我的heroku应用程序上运行任何命令(迁移,控制台等)

时间:2014-03-28 07:52:51

标签: ruby-on-rails ruby heroku

我使用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上运行良好。

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

3 个答案:

答案 0 :(得分:9)

因此,在尝试了许多事情之后,为了不尝试明显的事情而让自己头脑发热......我从environment / production.rb文件中删除了以下行:

config.active_record.dump_schema_after_migration = false

此后它在heroku上运行良好。

答案 1 :(得分:7)

Rails 4.0.4中不存在配置dump_schema_after_migration

您收到错误是因为您最初使用Rails v4.1.0rc1部署并稍后切换到v4.0.4。真正发生的是当你使用rails 4.1.0rc生成应用程序时,生成器将config 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

答案 2 :(得分:0)

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

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

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

这将是Rails 4.1.0的一个问题,但我需要尝试一点