重新运行Django数据迁移 [英] Rerun a Django data migration

查看:72
本文介绍了重新运行Django数据迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Django 1.8+上重新运行数据迁移?如果相关,我的迁移编号为0011_my_data_migration.py,是最新的迁移。

How would I rerun a data migration on Django 1.8+? If relevant, my migration is numbered 0011_my_data_migration.py and is the latest migration.

推荐答案

在要重新运行的迁移之前,请先恢复迁移。

Fake back to the migration before the one you want to rerun.

./manage.py migrate --fake yourapp 0010_my_previous_data_migration

然后重新运行迁移。

./manage.py migrate yourapp 0011_my_data_migration

然后,您可以伪造回您已运行的最新迁移。在您的情况下,您说0011是最新的,因此可以跳过此阶段。

Then you can fake back to the most recent migration that you have run. In your case, you said that 0011 was the latest, so you can skip this stage.

./manage.py migrate --fake yourapp 0014_my_latest_data_migration

请注意,根据数据库的状态和迁移的内容,重新运行这样的迁移可能会导致错误。请注意有关文档的警告 -伪造选项:

Note that depending on the state of your database and the contents of the migrations, rerunning a migration like this might cause errors. Note the warning in the docs about the --fake option:


这是供高级用户使用的如果他们正在手动应用更改,则直接为当前迁移状态;请注意,使用-fake 冒着将迁移状态表置于需要手动恢复以使迁移正确运行的状态的风险。

This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes; be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.

这篇关于重新运行Django数据迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆