rake db:migrate db:reset 和 db:schema:load 的区别 [英] Difference between rake db:migrate db:reset and db:schema:load
问题描述
rake db:migrate
和 rake db:reset
之间的区别在我的脑海中非常清楚.我不明白的是 rake db:schema:load
与前两者有何不同.
The difference between rake db:migrate
and rake db:reset
is pretty clear in my head. The thing which I don't understand is how rake db:schema:load
different from the former two.
只是为了确保我在同一页面上:
Just to be sure that I am on the same page:
rake db:migrate
- 运行尚未运行的迁移.rake db:reset
- 清除数据库(大概做了一个rake db:drop
+rake db:create
+rakedb:migrate
) 并在新数据库上运行迁移.
rake db:migrate
- Runs the migrations which haven't been run yet.rake db:reset
- Clears the database (presumably does arake db:drop
+rake db:create
+rake db:migrate
) and runs migration on a fresh database.
如果我的理解有误,请帮助澄清.
Please help to clarify, if my understanding has gone wrong.
推荐答案
db:migrate 运行尚未运行的(单个)迁移.
db:migrate runs (single) migrations that have not run yet.
db:create 创建数据库
db:drop 删除数据库
db:schema:load 在现有数据库中按照 schema.rb 创建表和列.这将删除现有数据.
db:schema:load creates tables and columns within the existing database following schema.rb. This will delete existing data.
db:setup 执行 db:create、db:schema:load、db:seed
db:setup does db:create, db:schema:load, db:seed
db:reset 执行 db:drop、db:setup
db:reset does db:drop, db:setup
db:migrate:reset 执行 db:drop、db:create、db:migrate
db:migrate:reset does db:drop, db:create, db:migrate
通常,您会在通过新的迁移文件更改架构后使用 db:migrate(这仅在数据库中已有数据时才有意义).db:schema:load 在您设置应用程序的新实例时使用.
Typically, you would use db:migrate after having made changes to the schema via new migration files (this makes sense only if there is already data in the database). db:schema:load is used when you setup a new instance of your app.
希望能帮到你.
rails 3.2.12 更新:
UPDATE for rails 3.2.12:
我刚查了源码,现在依赖是这样的:
I just checked the source and the dependencies are like this now:
db:create 为当前环境创建数据库
db:create creates the database for the current env
db:create:all 为所有环境创建数据库
db:create:all creates the databases for all envs
db:drop 删除当前环境的数据库
db:drop drops the database for the current env
db:drop:all 删除所有环境的数据库
db:drop:all drops the databases for all envs
db:migrate 为尚未运行的当前环境运行迁移
db:migrate runs migrations for the current env that have not run yet
db:migrate:up 运行一个特定的迁移
db:migrate:down 回滚一个特定的迁移
db:migrate:status 显示当前的迁移状态
db:rollback 回滚上次迁移
db:forward 将当前模式版本推进到下一个
db:forward advances the current schema version to the next one
db:seed(仅)运行 db/seed.rb 文件
db:seed (only) runs the db/seed.rb file
db:schema:load 将架构加载到当前环境的数据库中
db:schema:load loads the schema into the current env's database
db:schema:dump 转储当前 env 的架构(并且似乎也创建了数据库)
db:schema:dump dumps the current env's schema (and seems to create the db as well)
db:setup 运行 db:schema:load, db:seed
db:setup runs db:schema:load, db:seed
db:reset 运行 db:drop db:setup
db:reset runs db:drop db:setup
db:migrate:redo 运行 (db:migrate:down db:migrate:up) 或 (db:rollback db:migrate) 取决于指定的迁移
db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:rollback db:migrate) depending on the specified migration
db:migrate:reset 运行 db:drop db:create db:migrate
db:migrate:reset runs db:drop db:create db:migrate
有关更多信息,请查看 https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/railties/databases.rake(适用于 Rails 3.2.x)和 https://github.com/rails/rails/blob/v4.0.5/activerecord/lib/active_record/railties/databases.rake(适用于 Rails 4.0.x)
For further information please have a look at https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/railties/databases.rake (for Rails 3.2.x) and https://github.com/rails/rails/blob/v4.0.5/activerecord/lib/active_record/railties/databases.rake (for Rails 4.0.x)
这篇关于rake db:migrate db:reset 和 db:schema:load 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!