Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create another user immediately after creating one! #91

Open
BSiddharth opened this issue Jun 5, 2021 · 3 comments
Open

Cannot create another user immediately after creating one! #91

BSiddharth opened this issue Jun 5, 2021 · 3 comments

Comments

@BSiddharth
Copy link

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
Copy link

dubesar commented Jun 7, 2021

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

@BSiddharth
Copy link
Author

BSiddharth commented Jun 7, 2021

@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
Copy link

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants