104

I noticed that when generating data migration in Rails 5, some people use rails db:migrate over rake db:migrate. Can someone explain the difference between the rails and the rake command in database migration? Does it mean the rake command is obsolete in Rails 5?

1 Answer 1

193

Rails core team decided to have consistency by enabling rails command to support everything that rake does. See PR Implement rake proxy for rails cli #22288

For example, in Rails 5, commands like db:migrate, db:setup, db:test etc., which are part of the rake command in Rails 4, are now being supported by the rails command. However, you can still choose to use rake to run those commands similar to how they were run in Rails 4. This is because the Rails community has introduced Rake Proxy instead of completely moving the command options from Rake to Rails.

What happens internally is that when rails db:migrate command is executed, Rails checks if db:migrate is something that rails natively supports or not. In this case, db:migrate is not natively supported by Rails, so Rails delegates the execution to Rake via Rake Proxy.

If you want to see all the commands that are supported by Rails in Rails 5, then you can get a long list of options by executing rails --help.

Sign up to request clarification or add additional context in comments.

3 Comments

Any idea if there is a way to use the new syntax in a Rails 4 project?
@GregBlass You can includes module of rails 5 in to rails 4 to use it. but i don't think so you can use rails 5 syntax .
Rails 6 deprecates the rake-commands; At least some of them; rake dev:cache, rake notes and rake routes. They will be removed in Rails 6.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.