Rails db: migrate vs rake db: migrate

我是新来的。我注意到,在 Rails 5中生成数据迁移时,有些人使用 rails db:migrate而不是 rake db:migrate。有人能解释一下在数据库迁移中 Railsvs rake 命令之间的区别吗?这是否意味着 rake 命令在 Rails5中已经过时了?

非常感谢

24267 次浏览

Rails core team decided to have consistency by enabling rails command to support everything that rake does.

For example in Rails 5 commands like db:migrate, db:setup, db:test etc which are part of rake command in Rails 4 are now being supported by 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 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 is supported by rails in Rails 5 then you can get a long list of options by executing rails --help.