Open BSiddharth opened 3 years ago
i too faced this error, how to solve this error?
@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
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`
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