heroku run rake db:migrate在键入控制台时正常工作,但在通过rake任务运行时不能正常工作

时间:2012-09-28 21:05:49

标签: ruby-on-rails heroku rake dbmigrate

我有以下任务:

task :migrate_test => :environment do
   puts 'Running database migrations ...'
   puts `heroku run rake db:migrate --app my-app`
end

当我在控制台中运行heroku run rake db:migrate --app my-app时,迁移会成功进行。但是,当我运行rake migrate_test时,收到以下错误:


Running database migrations ...
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:371:in `new'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:371:in `search'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:361:in `gems_size'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:159:in `start'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:159:in `map'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:159:in `start'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:128:in `resolve'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:127:in `catch'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/resolver.rb:127:in `resolve'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/definition.rb:182:in `resolve'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/definition.rb:113:in `specs'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/definition.rb:162:in `specs_for'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/definition.rb:151:in `requested_specs'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/environment.rb:23:in `requested_specs'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/runtime.rb:11:in `setup'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler.rb:116:in `setup'
    from /Users/Will/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.0/lib/bundler/setup.rb:17

我认为它与rake运行任务有关,这个任务在一个找不到路径的不同进程中,但是无法找到解决方法。

2 个答案:

答案 0 :(得分:0)

您的代码没有错。请参阅this issue on GitHub

只需更新rubygems和RVM。甚至更好:使用rbenv

答案 1 :(得分:0)

解决方案是升级Heroku工具带。我仍然收到错误/Users/Will/.rvm/gems/ruby-1.9.3-p194@global/bin/rake: No such file or directory,但我猜工具带足够聪明,可以补偿。最新的工具带可以在这里找到:https://toolbelt.heroku.com/

我还建议在rake任务中使用exec ...而不是puts ...,因为您将能够实时查看进度。