Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

ruby-on-rails - 如何回滚特定的迁移?(How to rollback a specific migration?)

I have the following migration file db\migrate\20100905201547_create_blocks.rb

(我有以下迁移文件db\migrate\20100905201547_create_blocks.rb)

How can I specifically rollback that migration file?

(如何专门回滚该迁移文件?)

  ask by AnApprentice translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
rake db:rollback STEP=1

Is a way to do this, if the migration you want to rollback is the last one applied.

(如果要回滚的迁移是应用的最后一个迁移,则可以这样做。)

You can substitute 1 for however many migrations you want to go back.

(您可以将1替换为您想要返回的许多迁移。)

For example:

(例如:)

rake db:rollback STEP=5

Will also rollback all the migration that happened later (4, 3, 2 and also 1).

(还将回滚稍后发生的所有迁移(4,3,2和1)。)

To roll back all migrations back to (and including) a target migration, use: (This corrected command was added AFTER all the comments pointing out the error in the original post)

(要将所有迁移回滚到(并包括)目标迁移,请使用:(在所有注释指出原始帖子中的错误之后添加了此更正的命令))

rake db:migrate VERSION=20100905201547

In order to rollback ONLY ONE specific migration (OUT OF ORDER) use:

(为了仅回滚一个特定的迁移(OUT OF ORDER),请使用:)

rake db:migrate:down VERSION=20100905201547

Note that this will NOT rollback any interceding migrations -- only the one listed.

(请注意,这不会回滚任何中间迁移 - 仅列出所迁移的迁移。)

If that is not what you intended, you can safely run rake db:migrate and it will re-run only that one, skipping any others that were not previously rolled back.

(如果这不是你想要的,你可以安全地运行rake db:migrate ,它将只重新运行那个,跳过之前没有回滚过的任何其他的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...