django - PostgreSQL Django 迁移错误-域已存在

标签 django postgresql

我已经建立了一个新的 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/

相关文章:

django - 如何在查询性能目的中使用 Django 分页器?

ruby-on-rails - 计算rails postgresql查询中的时间差

Django 的 {{ csrf_token }} 仅输出 token 值,没有隐藏的输入标记

mysql - 请求设置 DATABASES,但在我的 Django 项目中设置未配置错误

python - Django / python : How do you start a new process in Python?

python - 模型对象没有属性保存

postgresql:带有选择查询的 INSERT INTO 语句

postgresql - 在 Mac 上切换到 postgres 用户

sql - 选择在 Rails 中创建的最后一个唯一多态对象

sql - 如何返回满足连续 EXACTLY 3 次出现条件的 ID 行?