开发者

Rake aborted! Uninitialized constant Rake::DSL on Heroku

开发者 https://www.devze.com 2023-03-21 02:56 出处:网络
When trying to rake db:migrate on Heroku. I\'m getting the following error. rake aborted! uninitialized constant Rake::DSL

When trying to rake db:migrate on Heroku. I'm getting the following error.

rake aborted!
uninitialized constant Rake::DSL

From what I've gathered this seems to be a bug with Rake 0.9.2. If I do "gem list" locally only Rake (0.8.7) appears to be installed.

I've tried adding "gem 'rake', '0.8.7'" to my gem file and running bundle install but then I get the foll开发者_开发问答owing error.

You have requested:
rake = 0.8.7

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

If I do run bundle update rake, it reverts back to 0.9.2, and I'm back where I started.

Am I missing something obvious here?


You should run commands with bundle exec to ensure your getting the proper dependencies. So run:

bundle exec rake db:migrate

For a more detailed post see Yehuda Katz blog post http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/

If you still continue to have problems there appears to be several other people with the same issue How to fix the uninitialized constant Rake::DSL problem on Heroku? which they resolved by adding the following to their Rakefile:

require 'rake/dsl_definition'
require 'rake'


I got this error when doing "heroku rake db:migrate".

In /app:

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

I fixed it by adding

require 'rake/dsl_definition' 

in RakeFile and then typed in

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

This one solved my problem. I didn't add gem 'rake', '0.8.7' in my gem file and my gem list shows rake (0.9.2, 0.8.7).


I have a blog post about this, You have already activated Rake 0.9.2. There are two ways to do this:

Only use the older version of Rake:

Check out your current Rake versions with $ gem list. See which versions of Rake you have and remove them all except for0.8.7. You can remove the gems with gem uninstall rake -v=0.9.1 or whatever version you need to remove.

Or just add a one liner to your Rake file:

Unless you have to use the older version of Rake it is easier to add this linerequire 'rake/dsl_definition' to your Rails's app Rakefile.

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


I used this to solve this very problem earlier without deleting any gems. This method will force your app to use Rake 0.8.7 which is more stable than 0.9+. You must run bundle update rake command after specifying the version of Rake to use so your gemfile.lock file is in sync with your gem file (if you skip this step Heroku will not let you push your code!)

In your gem file specify the version of Rake to use:

"rake", "0.8.7"

Then do:

bundle update rake

If this still isn't working for you, then do:

sudo gem uninstall rake


As with rich's answer (solving this problem without deleting any gems), but with a correction to your step 1., and a few additional steps:

  1. In the gem file specify:

    gem 'rake', '0.8.7'
    
  2. bundle install (Bundler documentation say to always 'bundle install' after changing your gem file)

  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

I got the same error without steps 3 and 4.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号