问题描述
首先,我问的是1.7中引入的Django迁移,而不是 south
。
First, I am asking about Django migration introduced in 1.7, not south
.
假设我有迁移 001_add_field_x
, 002_add_field_y
,并且它们都应用于数据库。现在,我改变主意,决定还原第二个迁移,并用另一个迁移 003_add_field_z
代替。
Suppose I have migrations 001_add_field_x
, 002_add_field_y
, and both of them are applied to database. Now I change my mind and decide to revert the second migration and replace it with another migration 003_add_field_z
.
换句话说,我要应用001和003,跳过002,我该怎么做?
In other words, I want to apply 001 and 003, skipping 002, how can I do this?
PS我知道我可以向后移植到001,但是在执行003移植并执行migration命令之后,将全部应用001到003,对吗?
P.S. I know I can migrate backwards to 001, but after I make the 003 migration and execute migrate command, 001 through 003 will all be applied, right?
推荐答案
您可以使用-fake
选项。
一旦还原为 0001
您可以运行
python manage.py migrate <app> 0002 --fake
然后运行
python manage.py migrate <app> #Optionally specify 0003 explicitly
仅适用于 0003
在这种情况下。
which would apply only 0003
in this case.
如果您不想对所有环境/其他开发人员都遵循此过程,则只需删除迁移文件,然后运行新文件即可。 makemigration
并提交该文件-是的,请使用 --fake运行
选项 migrate
If you do not want to follow this process for all the environment/other developers, you can just remove the migration files, and run a new makemigration
, and commit that file - and yes, do run migrate
with the --fake
option
这篇关于如何使用Django migration命令跳过迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!