唯一约束失败:通过电子邮件注册的auth_user.username [英] UNIQUE constraint failed: auth_user.username with registering with email
问题描述
与django-allauth集成成功运行了几天后,出现了这个奇怪的错误.我的方法与此项目相似. https://github.com/aellerton/demo-allauth-bootstrap
I am having this weird error after the integration with django-allauth successfully running for several days. My approach is similar to this project. https://github.com/aellerton/demo-allauth-bootstrap
此处使用电子邮件代替用户名,作为用户的唯一标识符.
Instead of the user_name, the email is used here as unique identifier of user.
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']
这是Model类:
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)
这是设置.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
任何人都可以帮助指出可能的错误吗?我不明白为什么它突然报告这样的错误.非常感谢!
Could anyone please help to point out possible mistakes? I could not understand why it suddenly reports such errors. Thanks a lot!
推荐答案
我终于找到了原因,并在这里列出.这可以帮助遇到与我相同情况的人.
I finally figured out the causes and list them here. This can help someone who run into the same situation as me.
- settings.py中的SITE_ID应该更改为与admin中的site_id相匹配
- 在自定义注册表单中添加注册.请看这里如何在使用django-allauth时自定义用户配置文件
这篇关于唯一约束失败:通过电子邮件注册的auth_user.username的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!