我如何解决'django_content_type已经存在'? [英] How can I resolve 'django_content_type already exists'?
问题描述
升级到django 1.8后,我收到迁移过程中的错误:
After upgrading to django 1.8 I'm recieving the error during migration:
ProgrammingError: relation "django_content_type" already exists
我对这个错误背后的背景感兴趣,但更重要的是,
如何我解决了吗?
I'd be interested in the background behind this error, but more importantly, How can I resolve it?
推荐答案
项目中的初始迁移有时可能会使用--fake-initial
Initial migrations on a project can sometimes be troubleshot using --fake-initial
python manage.py migrate --fake-initial
这是1.8的新功能。在1.7中,-fake-initial是一个默认的默认值,但在1.8中是明确的。
It's new in 1.8. In 1.7, --fake-initial was an implicit default, but explicit in 1.8.
从文档:
如果所有具有由该迁移中的所有CreateModel操作创建的所有模型的名称的数据库表已存在,则--fake-initial选项可用于允许Django跳过应用程序的初始迁移。此选项旨在在首先针对预先使用迁移的数据库运行迁移时使用。但是,此选项不会检查匹配的数据库模式超出匹配的表名称,因此只有确信现有模式与初始迁移中记录的模式相匹配,才可以使用。
The --fake-initial option can be used to allow Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for matching database schema beyond matching table names and so is only safe to use if you are confident that your existing schema matches what is recorded in your initial migration.
https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
这篇关于我如何解决'django_content_type已经存在'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!