2011-07-18 35 views
6

尝试rake db:migrateHeroku。我收到以下错误。耙子中止!在Heroku上未初始化的常量Rake :: DSL

rake aborted! 
uninitialized constant Rake::DSL 

从我收集的,这似乎是与Rake 0.9.2的错误。如果我在本地执行“gem list”,则只会安装Rake(0.8.7)。

我已经尝试在我的gem文件中添加“gem'rake','0.8.7'”并运行bundle安装,但随后出现以下错误。

You have requested: 
rake = 0.8.7 

The bundle currently has rake locked at 0.9.2. 
Try running `bundle update rake` 

如果我运行bundle update rake,它将恢复为0.9.2,和我回来了,我开始了。

我在这里错过了一些明显的东西吗?

回答

10

您应该使用bundle exec运行命令以确保您获得正确的依赖关系。这样跑:

bundle exec rake db:migrate 

对于更详细的帖子看到耶胡达·卡茨的博客文章http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/

如果仍然有问题,似乎有其他几个人用同样的问题How to fix the uninitialized constant Rake::DSL problem on Heroku?他们通过将解决下面给他们的Rake文件:

require 'rake/dsl_definition' 
require 'rake' 
1

我有一个博客张贴关于这一点,You have already activated Rake 0.9.2。有两种方法可以做到这一点:

仅使用耙的旧版本:

退房当前的耙版本的$ gem list。查看您拥有哪个版本的Rake,并将其全部删除,但0.8.7除外。您可以使用gem uninstall rake -v=0.9.1或任何需要删除的版本删除宝石。

或者只是一个衬垫添加到您的Rake文件:

除非你有使用旧版本的斜掠更容易此行require 'rake/dsl_definition'添加到您的Rails的应用Rake文件。

require File.expand_path('../config/application', __FILE__) 
require 'rake/dsl_definition' 
require 'rake' 
0

我以前用这个来解决这个问题,而不删除任何宝石。此方法将强制您的应用使用比0.9+更稳定的Rake 0.8.7。在指定要使用的Rake版本后,您必须运行bundle update rake命令,以便您的gemfile.lock文件与您的gem文件同步(如果您跳过此步骤,Heroku不会让您推送您的代码!)

在你的宝石文件中指定的Rake版本使用方法:

"rake", "0.8.7" 

然后做:

bundle update rake 

如果仍然不能为你工作,然后做:

sudo gem uninstall rake 
0

rich's answer(解决此问题而不删除任何宝石)一样,但对步骤1进行了更正,和一些额外的步骤:

  1. 在创业板上市文件中注明:

    gem 'rake', '0.8.7' 
    
  2. bundle install(捆扎机文件说永远改变你的宝石文件后, '包安装')

  3. git commit -am "Fixed heroku rake problem by specifying rake 0.8.7 in Gemfile"

  4. git push heroku

  5. heroku rake db:migrate

我没有步骤3和4

3

做 “的Heroku耙分贝:迁移” 当我得到这个错误了同样的错误。

/app

rake aborted! 
uninitialized constant Rake::DSL 
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2482:in `const_missing' 
.... 
... 
.... 
.. 
etc... 

我固定它通过增加

require 'rake/dsl_definition' 
在Rake文件

,然后在

bundle update rake 
git add . 
git commit -m "Change RakeFile" 
git push heroku 
heroku rake db:migrate 

这一个解决我的问题类型。我没有在我的创业板文件 中添加gem 'rake', '0.8.7',我的宝石列表显示耙子(0.9.2,0.8.7)。

+0

谢谢mamonluk,即使我也有同样的问题为我工作:) –

相关问题