Django测试运行程序失败,出现IntegrityError

时间:2018-09-07 17:38:32

标签: django

当尝试运行Django测试时,该进程似乎在管理员发布迁移信号时失败。我找不到有关此特定错误的任何信息。似乎信号正在尝试创建一个已经存在的权限记录-但我没有使用此特定模型进行任何修改。

    Traceback (most recent call last):
    File "/Users/username/.virtualenvs/app_name/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
    psycopg2.IntegrityError: duplicate key value violates unique constraint "auth_permission_content_type_id_codename_01ab375a_uniq"
    DETAIL:  Key (content_type_id, codename)=(1, view_logentry) already exists.

已安装的应用程序:

Installed apps:

INSTALLED_APPS = [
'admin_view_permission',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.messages',
# Disable Django's own staticfiles handling in favour of WhiteNoise, for
# greater consistency between gunicorn and `./manage.py runserver`. See:
# http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'whitenoise.runserver_nostatic',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'rest_framework_xml',
'allauth',
'allauth.account',
'rest_auth.registration',
'django_extensions',
'django_celery_beat',
'django_celery_results',
'raven.contrib.django.raven_compat',
'corsheaders']

我还没有设置任何测试类,这就是为什么这个错误特别令人困惑的原因。

1 个答案:

答案 0 :(得分:1)

您应该从admin_view_permission中删除INSTALLED_APPS,此软件包不建议使用Django 2.1