django-rest-framework-passwordless icon indicating copy to clipboard operation
django-rest-framework-passwordless copied to clipboard

Cannot create another user immediately after creating one!

Open BSiddharth opened this issue 3 years ago • 3 comments

If I try to create another user after I have already created one this error pops up django.db.utils.IntegrityError: UNIQUE constraint failed: auth_user.username

BSiddharth avatar Jun 05 '21 17:06 BSiddharth

i too faced this error, how to solve this error?

dubesar avatar Jun 07 '21 07:06 dubesar

@dubesar not sure I just implemented my own system. You can always implement your own user where username does not needs to be unique but not sure if that is what is required here cuz it is not specified in the docs to do so. So I just implemented this from scratch gives me more control that way

BSiddharth avatar Jun 07 '21 14:06 BSiddharth

I had this issue when I used unique=True. normally when using a custom user model the username field has to be unique. This is a work around:

Custom user model

mobile = PhoneNumberField(validators=[validate_phone_is_unique], blank=True, null=True)

validate_phone_is_unique

` def validate_phone_is_unique(phone):

is_phone = models.User.objects.filter(phone_number=phone).exists()
if phone != "" and is_phone:
    raise IntegrityError("This Phone Number Exists")
else:
    return phone`

jaymes15 avatar Sep 17 '21 06:09 jaymes15