aaronn / django-rest-framework-passwordless

Passwordless Auth for Django REST Framework
MIT License
708 stars 154 forks source link

Cannot create another user immediately after creating one! #91

Open BSiddharth opened 3 years ago

BSiddharth commented 3 years ago

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

dubesar commented 3 years ago

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

BSiddharth commented 3 years ago

@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

jaymes15 commented 2 years ago

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`