I'm writing a site on django. And I ran into a problem, when I want to add a superuser, the following error occurs:
django.db.utils.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (pbkdf2_sha256$390000$gajFrJerChyUlrAwZWzfkS$gmZ4GQTavfwqlV5jaPl ..., null, t, admin_dima, , , t, t, 2023-01-07 22:12:28.
743122 00, null, , [email protected], , ).
I think it has something to do with the fact that I'm using a model that inherits from AbstractUser Here is my model:
class JobseekerRegisterInfo(AbstractUser):
id = models.IntegerField(primary_key=True)
phone_number = PhoneNumberField()
email = models.EmailField(unique=True)
full_name = models.CharField(max_length=120)
hashed_password = models.CharField(max_length=200)
def __str__(self):
return self.full_name
And I commented for a while in the settings.py file and the main urls.py file the link to the admin page, and before that, how to create a superuser, I uncommented it again
CodePudding user response:
Use an automatic primary key field for id
. For example, models.BigAutoField
(Django docs) is a 64-bit integer under the hood:
class JobseekerRegisterInfo(AbstractUser):
id = models.BigAutoField(primary_key=True)
...