最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

django - DRF allauth email authentication unique constraint failed - Stack Overflow

programmeradmin2浏览0评论

I am trying to implement an email authentication with djangorestframework, dj-rest-auth and allauth.

Here is my custom user model

class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_("email address"), unique=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = []

    objects = CustomUserManager()

    def __str__(self):
        return self.email

Here is my settings.py

...
AUTH_USER_MODEL = "users.CustomUser"

ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_LOGIN_METHODS = {'email'}
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
...

It registers a new user as expected if the there is not an existing user with the same email, but if I try to create an user with an email that has already been registered, I got this error:

django.db.utils.IntegrityError: UNIQUE constraint failed: users_customuser.email

I expected allauth to handle this error since it does with username authentication. Am I missing something? Should I handle this error manually?

发布评论

评论列表(0)

  1. 暂无评论