Hi I try make superuser to login my admin panel but I recieved this error while making superuser:
django.db.utils.OperationalError: no such column: accounts_user.password1
and this is my model:
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
username = models.CharField(unique=True, max_length=10)
email = models.EmailField()
password1 = models.CharField(max_length=20)
password2 = models.CharField(max_length=20)
is_publisher = models.BooleanField(default=False)
def change_user_type(self):
if self.is_publisher:
self.is_superuser = True
self.save()
You do not need to store two password in db. Just check those in FE validation.Since you inherit the AbstractUser automatically you are getting password field by default.
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
email = models.EmailField(unique=True)
is_publisher = models.BooleanField(default=False)
def change_user_type(self):
if self.is_publisher:
self.is_superuser = True
self.save()