gpt4 book ai didi

python - 如何解决 'django_content_type already exists' ?

转载 作者:IT老高 更新时间:2023-10-28 21:44:39 29 4
gpt4 key购买 nike

升级到 django 1.8 后,我在迁移过程中收到错误消息:

ProgrammingError: relation "django_content_type" already exists

我会对这个错误背后的背景感兴趣,但更重要的是,我该如何解决?

最佳答案

有时可以使用 --fake-initial 解决项目的初始迁移问题

python manage.py migrate --fake-initial

这是 1.8 中的新功能。在 1.7 中,--fake-initial 是一个隐式默认值,但在 1.8 中是显式的。

来自文档:

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

关于python - 如何解决 'django_content_type already exists' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29760817/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com