what does it do by "bundle exec rake db:migrate"? - ruby-on-rails

from my research, bundle exec is responsible for executing a command in the context of a bundle.
anyway, I don't quite understand yet for what it does differently for just the command rake db:migrate comparing with bundle exec rake db:migrate.
for example in my case, I executed the first command, and what I got was the following errors:
$ rake db:migrate
(in c:/rails/rails_projects/soccerweb)
rake aborted!
uninitialized constant Rake::DSL
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `requ
ire'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `require'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `block in <class:TestUnitRailtie>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
block in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `b
lock in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `all'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `l
oad_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:103:
in `load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurabl
e.rb:30:in `method_missing'
c:/rails/rails_projects/soccerweb/Rakefile:7:in `<top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
c:/Ruby192/bin/rake:31:in `<main>'
but when I used "bundle exec" preceding that "rake db:migrate" command, everything just worked for me gracefully!
anyone can shed some light on me?

bundle exec rake runs the version of rake which you've specified in your Gemfile. The default version of rake, the one which can be found in your $PATH, might be different than one executed by bundle exec rake.
The problem you've experienced has been covered in a separate question. Your bundle exec rake most probably runs rake 0.8.7 and rake from your $PATH is a newer version which is affected by this problem.
Quoting from man bundle exec:
bundle exec makes a number of changes to the shell environment, then executes the command you specify in full.
(...)
put the directory containing executables (like rails, rspec, rackup) for your bundle on $PATH

Bundler solves gem dependencies for you. You can find read their rationale page for an explanation about their approach.

Related

Cannot migrate on Heroku

I'd like to migrate database to production environment on Heroku.
I typed the following code, however I got error. I have no idea what to do. I'm looking forward to your advice. Thank you for your kindness.
$ heroku run rake db:migrate
Running `rake db:migrate --trace` attached to terminal... up, run.2338
rake aborted!
LoadError: libruby.so.2.2: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg_ext.so
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg.rb:4:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:134:in `require'
/app/config/application.rb:7:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/app/bin/rake:8:in `<main>'
Have you tried running migration directly from the bash inside the heroku server? If not, try the following...
heroku run bash --app your_app_name_goes_here
bundle exec rake db:migrate
First line of code opens the bash command terminal and the second one migrates the db as usual.
This would not be the suggested solution. But, in case you DO NOT care about losing data in the database, you can try and reset the database first and try again. Again, don't do this unless you are willing to lose existing data!
heroku pg:reset DATABASE
heroku run rake db:migrate
However you can perform this via bash as before.
Hope this helps you out.
You can run a dyno in the background using heroku run:detached. Unlike heroku run, these dynos will send their output to your logs instead of your console window. You can use heroku logs to view the output from these commands:$ heroku run:detached rake db:migrate
Running rake db:migrate... up, run.2
Use 'heroku logs -p run.2' to view the log output.

rake db:migrate is being aborted due to rake version difference [duplicate]

This question already has answers here:
You have already activated X, but your Gemfile requires Y
(12 answers)
Closed 8 years ago.
I am getting the error
rake db:migrate --trace
rake aborted!
You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
/Users/iang/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup'
/Users/iang/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
/Users/iang/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
/Users/iang/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/setup.rb:7:in `<top (required)>'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:116:in `require'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:116:in `rescue in require'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:122:in `require'
/Users/iang/code/Projects/work/startco/config/boot.rb:4:in `<top (required)>'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/iang/code/Projects/work/startco/config/application.rb:1:in `<top (required)>'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/iang/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
/Users/iang/code/Projects/work/startco/Rakefile:4:in `<top (required)>'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/rake_module.rb:25:in `load'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:93:in `load_rakefile'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:77:in `block in run'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.1/bin/rake:33:in `<top (required)>'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/bin/rake:23:in `load'
/Users/iang/.rvm/gems/ruby-2.0.0-p247/bin/rake:23:in `<main>'
used bundle and it did not fix the problem... any ideas as to help fix this problem?
I hit the same error. Running bundle update solved it.
Update: As suggested by TuK bundle update rake is the way to go.
You want to use bundle exec:
bundle exec rake db:migrate
Or, if you're using Rails 4 binstubs:
./bin/rake db:migrate
I got this error message while deploying to production with capistrano. To fix it I executed the following on my production server:
gem update rake
bundle update rake fixed the issue for me.
I had the same error but running bundle update rake didn't work for me. This answer worked for me. You have to remove your Gemfile.lock:
rm Gemfile.lock
then re-bundle:
bundle install
I got the answer.
Why we got this error?
For the rake version of our OS is different from the version of our project. When we set the same. Everything gets ok!
The light way is set the same version in our Gemfile. And make sure keep all the project the same rake!
gem 'rake', '10.2.2' #forking error! force the version the same with our OS and all projects!!!
I hope U see what I said and the real reason of this error. Then we will have more resolutions such as "bundle update rake". Thanks!
You can run this command
bundle exec rake db:migrate
just install old version by command: gem install rake -v '10.1.0'

bundle exec rake db:create:all, errors caused by 2 different versions of rake gem, not sure where to go from here

I'm trying to bundle exec rake db:create:all
I found that I have two versions of the rake gem:
rake (10.1.0, 0.9.6)
Author: Jim Weirich
Homepage: http://rake.rubyforge.org
License: MIT
Installed at (10.1.0): /Users/david/.rvm/gems/ruby-2.0.0-p247#global
(0.9.6, default): /Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0
I think there may be an issue with the two different locations of the gems; 10.1 is at #global, and 0.9.6 is not. I think the solution may lay here because...
The trace first looks at the directories in 0.9.6 and then the last two lines look in 10.1:
dn0a158988:portfolio davidngo$ bundle exec rake db:create:all --trace
rake aborted!
cannot load such file -- /Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/boot
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/application.rb:1:in `require'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/config/application.rb:1:in `<top (required)>'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/Rakefile:5:in `require'
/Users/davidngo/Desktop/Coding/RoR_Practice/portfolio/Rakefile:5:in `<top (required)>'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/rake_module.rb:25:in `load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:604:in `raw_load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:89:in `block in load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:88:in `load_rakefile'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:72:in `block in run'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:160:in `standard_exception_handling'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rake/application.rb:70:in `run'
/Users/davidngo/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-0.9.6/bin/rake:37:in `<top (required)>'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `load'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247#global/bin/rake:23:in `<main>'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/Users/davidngo/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
I specified in my Gemfile `gem 'rake', '0.9.6'
I ran bundle update to update the Gemlock file
Thank you in advance -- any help would be appreciated!
Thought: I'm going to try to uninstall the 10.1 version of rake and see if it'll work.
I don't think it's the multiple versions of rake. The bundle exec bit should do the right thing. Are you missing the /config/boot.rb file referred to at /config/application.rb:1?

rake assets:precompile aborting

I was able to precompile assets an hour ago, but now the rake task is aborting. I also check it on another app, and it's aborting there too. I had interrupted a push to Heroku rather abruptly, and haven't been able to precompile since then.
bundle exec rake assets:precompile
rake aborted!
undefined method `prerequisites' for nil:NilClass
/Users/mm/Sites/quoraquora/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
Line 7 of the rake file is this code Enki::Application.load_tasks
require File.expand_path('../config/application', __FILE__)
Enki::Application.load_tasks
I also did a bundle update, but it didn't change anything. Prior to trying to run the rake task, I abruptly stopped a push to Heroku because I had forgot to compile the assets. Not sure if that could have caused anything. Interestingly, the application still runs on localhost.
I tried to run bundle exec rake assets:precompile on another app, and I also got an error, albeit a different one that says it can't locate 'uglifier' even though that gem is installed.
bundle exec rake assets:precompile
/Users/mm/.rbenv/versions/1.9.3-p327/bin/ruby /Users/mm/.rbenv/versions/1.9.3-p327/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
cannot load such file -- uglifier
(in /Users/mm/Sites/railshangman/app/assets/javascripts/admin.js)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/mm/.rbenv/versions...]
Tasks: TOP => assets:precompile
This is the full trace from the first abort. Can anyone explain? The problem seems to be beyond the scope of one specific app, because bundle exec rake assets:precompile was working fine on every app one hour ago.
Macintosh-3:coffeelover mm$ bundle exec rake assets:precompile --trace
rake aborted!
undefined method `prerequisites' for nil:NilClass
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rspec-rails-2.0.1/lib/rspec/rails/tasks/rspec.rake:3:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rspec-rails-2.0.1/lib/rspec-rails.rb:10:in `block in <class:Railtie>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `instance_exec'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `block in load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `each'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie.rb:184:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:423:in `block in load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/railties.rb:8:in `each'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/railties.rb:8:in `all'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:423:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:145:in `load_tasks'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/mm/Sites/coffeelover/Rakefile:7:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:583:in `raw_load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:89:in `block in load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:88:in `load_rakefile'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:72:in `block in run'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/mm/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/mm/.rbenv/versions/1.9.3-p327/bin/rake:23:in `load'
/Users/mm/.rbenv/versions/1.9.3-p327/bin/rake:23:in `<main>'
Try updating your version of rake and rspec-rails
bundle update rspec-rails
bundle update rake
I had to update my version of rspec-rails to 2.6.0 (from 2.0). Strangely, this did not happen automatically if I deleted the gemfile.lock and did bundle update. I had to manually set the version in the Gemfile.

Problems using rake db:migrate on railstutorial.org chapter 2

I am following the rails tutorial at railstutorial.org
I'm in chapter 2 and tried to migrate the database using rake as per the instructions: "To proceed with the demo application, we first need to migrate the database using Rake (Box 2.1)":
$ rake db:migrate
This did not work and I received the following error:
C:\Users\USER1\rails_project\demo_app>rake db:migrate
(in C:/Users/USER1/rails_project/demo_app)
rake aborted!
uninitialized constant Rake::DSL
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
C:/Users/USER1/rails_project/demo_app/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
C:/Ruby192/bin/rake:31:in `<main>'
How can I resolve this?
This is a problem with the new (just released) version of rake. You can solve it by downgrading rake to 0.8.7. It's the simpler solution for a tutorial. See Rake 0.9.0 'undefined method 'task' ' and answers to that question.
You might add rake 0.8.7 to your Gemfile, like:
gem 'rake', '0.8.7'
And in the terminal you should run with
bundle exec rake db:migrate
And you are ready to follow, i hope this will help you.
I know you would have solved this issue long back but just in case anyone needs to know Rake .9.0 breaks Rails and several other things, you need to either go back to previous version or update the latest one (11.1.2):
gem "rake", "11.1.2"
in your Gemfile.
And then just follow these commands:
$ bundle update rake
Then check the rake with:
$ bundle show rake
And it should show rake 11.1.2.
After this you can successfully run
$ bundle exec rake db:migrate
(PS: hope this helps someone :) )

Resources