我是 Rails 的新手.我注意到在 rails 5 中生成数据迁移时,有些人使用 rails db:migrate 而不是 rake db:migrate.有人可以解释数据库迁移中 rails 与 rake 命令之间的区别吗?这是否意味着 rake 命令在 rails 5 中已过时?
I'm new to rails. I noticed 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 vs rake command in database migration? Does it mean rake command is obsolete in rails 5?
非常感谢
推荐答案Rails 核心团队决定通过启用 rails 命令来支持 rake 所做的一切来保持一致性.
Rails core team decided to have consistency by enabling rails command to support everything that rake does.
例如在 Rails 5 命令中,如 db:migrate、db:setup、db:test 等,它们是 rake 命令的一部分Rails 命令现在支持 Rails 4.但是,您仍然可以选择使用 rake 来运行这些命令,类似于它们在 Rails 4 中的运行方式.这是因为 Rails 社区引入了 Rake 代理,而不是将命令选项从 rake 完全移动到 rails.
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.
内部发生的事情是,当 rails db:migrate 命令被执行时,Rails 会检查 db:migrate 是否是 Rails 原生支持的东西.在这种情况下,db:migrate 不受 rails 的原生支持,因此 Rails 通过 Rake 代理将执行委托给 Rake.
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.
如果您想查看 Rails 5 中 rails 支持的所有命令,那么您可以通过执行 rails --help 获得一长串选项.
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.
更多推荐
rails db:migrate vs rake db:migrate
发布评论