如何避免 ruby 中的错误回滚迁移?
我在迁移中的“self.drop”中有一个错误,因此我无法回滚到该迁移之后。 我如何从头开始并从迁移 001 开始构建? 另外,有没有办法做到这一点而不丢失我的数据(这只是测试,但仍然......)
i have a bug in a "self.drop" in a migration such that I cannot roll back past that migration. how can i start from scratch and build up from migration 001? also, is there a way to do this without losing my data (it's just testing, but still...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我意识到这是一个老问题,但恕我直言仍然相关。 如果您想从头开始重新创建数据库,则不会回滚并重新运行迁移,而只是这样做。
这将删除、创建数据库并使用所有迁移的当前组合状态填充数据库。 这是因为,在大型系统中,运行所有迁移可能不再有效。 但是,运行
schema.rb
将始终有效。我的建议还包括尽可能避免回滚迁移,除非您刚刚创建迁移并希望在将迁移推送到团队或任何部署之前进行一些添加/拼写错误/修复。
I realise this is an old question, but imho still relevant. If you want to recreate your database from scratch, one does not rollback and rerun migration, one just does
This will drop, create and fill the database with the current combined state of all the migrations. This is because, definitely in a large system, running all the migrations might no longer work. However, running the
schema.rb
will always work.My advice would also be to avoid rollback of migrations as much as possible, unless when you just created a migration and want to make some addition/typo/fix, before having pushed the migration to your team or any deployment.
它将重置您的数据库并运行所有迁移。 如果您不想丢失数据,可以使用插件 yaml_db 保存数据:
如果迁移过程中出现错误,您可以对其进行编辑,然后尝试回滚。
It will reset your database and run all migrations. If you don't want to lose your data you can save it using plugin yaml_db:
If you have an error in a migration you can edit it and then try to rollback.
您可以注释 self.down 迁移和回滚到以前的数据库版本中的所有语句。
然后使用 gui/web 数据库客户端手动应用更改,以在迁移之前匹配数据库架构。
之后您将能够再次运行迁移,并且您的数据不会丢失。
You can comment all statements in self.down migration and rollback to previous db version.
Then apply changes by hand using a gui/web db client to match db schema before migration.
After you will be able to run migration again and your data will not be lost.