如何使用 rake db:migrate 回滚一步
在 db/migrate
文件夹中添加迁移文件并运行 rake db:migrate
后,我想回到上一步,我想使用 VERSION=n< /code> 是正确的方法,但我不知道要使用的 n 的正确值。有没有命令可以查看当前n值?
如果有人能够提供有关如何使用 rake db:migrate 的完整说明,那就太好了。
After adding migration files in the db/migrate
folder and running rake db:migrate
, I want get back to the previous step, I think using VERSION=n
is the right way to do that, but I don't know the correct value of n to use. Is there any command to check the current n value?
It would be great if anyone could provide full instructions on how to use rake db:migrate
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于初学者,
rake db:rollback
将使您后退一步,然后
rake db:rollback STEP=n
将使您回滚
n
次迁移,其中n
是您要回滚的最近迁移的数量。更多参考此处。
For starters
rake db:rollback
will get you back one stepthen
rake db:rollback STEP=n
Will roll you back
n
migrations wheren
is the number of recent migrations you want to rollback.More references here.
回滚最近的迁移:
回滚
n
个最近的迁移:您可以在 Rails 运行迁移指南。
还有更多内容:
rake db:migrate
- 运行所有尚未运行的迁移rake db:migrate VERSION=20080906120000
- 运行所有必要的迁移(向上或向下)获取给定版本rake db:migrate RAILS_ENV=test
- 在给定环境中运行迁移rake db:migrate:redo
- 回滚一个迁移并再次运行n
次迁移并再次运行它们rake db:migrate:up VERSION=20080906120000
-为给定的迁移运行up
方法rake db:migrate:down VERSION=20080906120000
- 为给定的迁移运行down
方法并回答关于从哪里获取迁移版本号的问题:
(来自 Rails 指南中的 运行迁移)
Roll back the most recent migration:
Roll back the
n
most recent migrations:You can find full instructions on the use of Rails migration tasks for rake on the Rails Guide for running migrations.
Here's some more:
rake db:migrate
- Run all migrations that haven't been run alreadyrake db:migrate VERSION=20080906120000
- Run all necessary migrations (up or down) to get to the given versionrake db:migrate RAILS_ENV=test
- Run migrations in the given environmentrake db:migrate:redo
- Roll back one migration and run it againrake db:migrate:redo STEP=n
- Roll back the lastn
migrations and run them againrake db:migrate:up VERSION=20080906120000
- Run theup
method for the given migrationrake db:migrate:down VERSION=20080906120000
- Run thedown
method for the given migrationAnd to answer your question about where you get a migration's version number from:
(From Running Migrations in the Rails Guides)
最好的方法是使用 down 或 up 再次运行特定迁移(在 Rails 4 中。这是变化)
现在如何获取时间戳。
走这条路
确定要恢复的迁移文件。从该文件名中选择时间戳。
Best way is running Particular migration again by using down or up(in rails 4. It's change)
Now how you get the timestamp.
Go to this path
Identify migration file you want to revert.pick the timestamp from that file name.
如果版本是
20150616132425
,则使用:If the version is
20150616132425
, then use:其他人已经回答了如何回滚,但您还问了如何识别迁移的版本号。
rake db:migrate:status
给出您的迁移版本、名称和状态(向上或向下)的列表/db/migrate
Other people have already answered you how to rollback, but you also asked how you could identify the version number of a migration.
rake db:migrate:status
gives a list of your migrations version, name and status (up or down)/db/migrate