我已经建立了一个新的 Django 项目(基于模板 django cookie cutter)但是在第一次尝试迁移数据库时出现了 postgres 错误
psycopg2.ProgrammingError: relation "django_site_domain_a2e37b91_uniq" already exists
我不清楚问题是什么或如何最好地诊断?
最佳答案
What is SITE_ID ?
Django was created from a set of scripts developed at a newspaper to publish content on multiple domains; using one single content base.
This is where the "sites" module comes in. Its purpose is to mark content to be displayed for different domains.
In previous versions of django, the startproject script automatically added the django.contrib.sites application to INSTALLED_APPS, and when you did syncdb, a default site with the URL example.com was added to your database, and since this was the first site, its ID was 1 and that's where the setting comes from.
Keep in mind that starting from 1.6, this framework is not enabled by default. So if you need it, you must enable it
The SITE_ID setting sets the default site for your project. So, if you don't specify a site, this is the one it will use.
解决方法:
增加SITE_ID
:
1. Increment `SITE_ID` variable in settings.py
2. python manage.py makemigrations
3. python manage.py migrate --run-syncdb
缺点:没有充分理由必须增加 SITE_ID
尝试在没有--run-syncdb
的情况下迁移:
1. python manage.py makemigrations
2. python manage.py migrate
注意:可能需要多次尝试才能生效。不确定为什么,可能是因为我正在删除 pvc
关于django - PostgreSQL Django 迁移错误-域已存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188467/