andrewcallahan
andrewcallahan

Reputation: 11

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?

Upvotes: 1

Views: 2404

Answers (3)

Nirupa
Nirupa

Reputation: 787

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 :) )

Upvotes: 0

igmarin
igmarin

Reputation: 443

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.

Upvotes: 1

Fabio
Fabio

Reputation: 19176

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.

Upvotes: 2

Related Questions