我将如何在 Django 1.8+ 上重新运行数据迁移?如果相关,我的迁移编号为 0011_my_data_migration.py 并且是最新的迁移。
最佳答案
在您要重新运行的那个之前假装回到迁移。
./manage.py migrate --fake yourapp 0010_my_previous_data_migration
然后重新运行迁移。
./manage.py migrate yourapp 0011_my_data_migration
然后您可以伪造回您运行的最近一次迁移。在你的情况下,你说 0011 是最新的,所以你可以跳过这个阶段。
./manage.py migrate --fake yourapp 0014_my_latest_data_migration
请注意,根据数据库的状态和迁移的内容,像这样重新运行迁移可能会导致错误。注意警告 in the docs关于 --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 - 重新运行 Django 数据迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31953587/