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

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

问题描述

如何在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 your app 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

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

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 1.8上重新运行数据迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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