Django 唯一约束失败:使用电子邮件注册的auth_user.username

Django 唯一约束失败:使用电子邮件注册的auth_user.username,django,django-allauth,Django,Django Allauth,在与django allauth集成成功运行了几天之后,我遇到了这个奇怪的错误。我的方法类似于这个项目。 此处使用电子邮件作为用户的唯一标识符,而不是用户名 IntegrityError at /accounts/signup/ UNIQUE constraint failed: auth_user.email Request Method: POST Request URL: http://localhost:8080/accounts/signup/ Django Version: 1.8

在与django allauth集成成功运行了几天之后,我遇到了这个奇怪的错误。我的方法类似于这个项目。

此处使用电子邮件作为用户的唯一标识符,而不是用户名

IntegrityError at /accounts/signup/
UNIQUE constraint failed: auth_user.email
Request Method: POST
Request URL: http://localhost:8080/accounts/signup/
Django Version: 1.8
Exception Type: IntegrityError
Exception Value:

UNIQUE constraint failed: auth_user.email
Exception Location: ~/web_dev/unicorn_dev/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py in execute, line 318
Python Executable: ~/web_dev/unicorn_dev/bin/python
Python Version: 3.4.3
Python Path:

['~/web_dev/unicorn_dev/funding',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
'~/web_dev/unicorn_dev/lib/python3.4/site-packages']
以下是模型类:

class AccountUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(('email address'), blank=False, max_length=255, unique=True)
    first_name = models.CharField(('first name'), max_length=40, blank=True, null=True, unique=False)
    last_name = models.CharField(_('last name'), max_length=40, blank=True, null=True, unique=False)
这是settings.py

ACCOUNT_USER_MODEL_USERNAME_FIELD = None /* user_name is not used, if not None, migration will report errors */
ACCOUNT_USERNAME_REQUIRED = False
#Enforce uniqueness of e-mail addresses.
ACCOUNT_USER_MODEL_EMAIL_FIELD = "email"
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD = "email"
以下是我所做的:

1. Deleting the whole database and re-migrating the database does not help at all. 
2. Checked this link https://github.com/pennersr/django-allauth/issues/1014

有人能帮忙指出可能的错误吗?我不明白为什么它突然报告了这样的错误。非常感谢

我终于找到了原因,并在这里列出了它们。这可以帮助那些遇到和我一样情况的人

  • 应更改settings.py中的SITE_ID以匹配admin中的SITE_ID
  • 在自定义注册表单中添加注册。请看这里