3

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']

Here is the Model class:

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)

Here is the 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"

Here is what I did:

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!

thinkdeep
  • 945
  • 1
  • 14
  • 32

1 Answers1

4

I finally figured out the causes and list them here. This can help someone who run into the same situation as me.

  1. SITE_ID in settings.py shall be changed to match the site_id in admin
  2. Add the signup in the custom sign up form. Please see here How to customize user profile when using django-allauth
thinkdeep
  • 945
  • 1
  • 14
  • 32