Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django throwing UNIQUE Constraint failed even after adding unique = False

I am developing a custom usermodel for my application in django, by using AbstractUser.
But I am getting a UNIQUE constraint failed error while using add user + from django admin.
I have also tried to add unique = False in the EmailField

class User(AbstractUser):
    id = models.BigAutoField(primary_key=True)
    rollno = models.CharField(null=True,unique=True,max_length=15)
    email = models.EmailField(blank=True,null=True,unique=False) 

Error :

....
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: Accounts_user.email
[28/Jun/2022 05:54:58] "POST /admin/Accounts/user/add/ HTTP/1.1" 500 233697

The add form does not have a email field, submits a blank email.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(PS : I can add user by signup form of my application, change user of django admin is also working.)\

>Solution :

in the above code, there should not be any problem with migrations. i think your old migrations are creating problem here. check your old migrations and delete them.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading