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

Rav*_*hal 3 ruby ruby-on-rails heroku

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

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

ravjohal$ heroku run rake db:migrate
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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)>'....
Run Code Online (Sandbox Code Playgroud)

这是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)>'
Run Code Online (Sandbox Code Playgroud)

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

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

Rav*_*hal 9

所以在尝试了很多东西之后,为了不尝试明显的东西而让自己头脑发热......我从环境/ production.rb文件中删除了以下行:

config.active_record.dump_schema_after_migration = false
Run Code Online (Sandbox Code Playgroud)

之后它在heroku上运行良好.


Emi*_*mil 7

配置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
Run Code Online (Sandbox Code Playgroud)

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

顺便说一句,我添加了dump_schema_after_migration配置到Rails代码.