如何从Django 1.7的初始迁移迁移回去?

问题:如何从Django 1.7的初始迁移迁移回去?

我用一些模型创建了一个新的应用程序,现在我发现一些模型没有经过深思熟虑。由于我尚未提交代码,因此明智的做法是将数据库迁移到最后的良好状态,并使用更好的模型重新进行迁移。在这种情况下,最后的良好状态是新应用程序不存在的数据库。

如何从Django 1.7的初始迁移迁移回去?

South一个可以这样做:

python manage.py migrate <app> zero

<app>将从迁移历史记录中清除并删除的所有表<app>

如何在Django 1.7迁移中做到这一点?

I created a new app with some models and now I noticed that some of the models are poorly thought out. As I haven’t committed the code the sensible thing would be to migrate the database to last good state and redo the migration with better models. In this case the last good state is database where the new app doesn’t exist.

How can I migrate back from initial migration in Django 1.7?

In South one could do:

python manage.py migrate <app> zero

Which would clear <app> from migration history and drop all tables of <app>.

How to do this with Django 1.7 migrations?


回答 0

您也可以使用Django 1.7+进行相同操作:

python manage.py migrate <app> zero

<app>将从迁移历史记录中清除,并删除所有的表<app>

有关更多信息,请参见django文档

You can do the same with Django 1.7+ also:

python manage.py migrate <app> zero

This clears <app> from migration history and drops all tables of <app>

See django docs for more info.


回答 1

您还可以使用版本号:

python manage.py migrate <app> 0002

来源:https : //docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate

you can also use the version number:

python manage.py migrate <app> 0002

Source: https://docs.djangoproject.com/en/1.7/ref/django-admin/#django-admin-migrate