Django keeps telling me that my superuser email violates unique constraint
I'm building a Django/DRF backend and keep getting this error when I try to create a superuser in cli:
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint `"users_useraccount_email_key"`
This is strange because I know that I'm using unique emails EVERY time I create a superuser.
After inspecting the error message further, I noticed that it said the above exception was a direct cause of the following exception:
... lots of venv related files
and then in my /users/managers.py, line 61
Which is just: user.save(using=self._db)
At the bottom of the error is:
django.db.utils.IntegrityError: duplicate key value violates unique constraint "users_useraccount_email_key"
DETAIL: Key (email)=(email@email.com) already exists.
I'm using Postgres and using Postgres to generate the UUID, NOT python.
class MyRandomUUID(Func):
class RandomUUID(Func):
template = 'GEN_RANDOM_UUID()'
# template = 'UUID_GENERATE_V4()'
output_field = 'UUIDField()'
I am on Ubuntu and my virtual env is using Python v3.8, Django v4.17 and DRF v3.15. I know these versions are aging but its what the commands installed w/o giving specific versions.
And I can no longer login to /admin either. It gives me this error(EVERY TIME): Please enter the correct email and password for a staff account. Note that both fields may be case-sensitive.
BEFORE this, I was able to successfully create superusers, login to /admin and perform basic CRUD.
What could be wrong:
- Versions are to old? Time to upgrade?
- Database/data is corrupted?
- Something is out of sync?
If you need me to post my /users/models.py and/or /users/managers.py, just let me know