在与 django-allauth 集成成功运行数天后,我遇到了这个奇怪的错误。我的方法类似于这个项目。 https://github.com/aellerton/demo-allauth-bootstrap
这里使用电子邮件代替用户名作为用户的唯一标识符。
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 匹配
- 在自定义注册表单中添加注册表。请看这里 How to customize user profile when using django-allauth
关于django - UNIQUE constraint failed : auth_user. username with registering with email,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33093754/