Is there any way to use the password field from my legacy DB to authenticate? I have implemented the custom user model as documented and and using USERNAME_FIELD = ‘email’ to authenticate with email. The createsuperuser function DOES prompt for email but errors without prompting for password with the below error.
django.db.utils.ProgrammingError: column accounts_users.password does not exist
LINE 1: SELECT “accounts_users”.“id”, “accounts_users”.“password”, "…
Edit: Custom User Model
class CardsUserManager(BaseUserManager):
def create_user(self, email, password, is_active=True, is_staff=False, is_superuser=False):
if not email:
raise ValueError("Users must have and email address!")
if not password:
raise ValueError("Users must have a password!")
user_obj = self.model(
email = self.normalize_email(email)
)
user_obj.set_password(password) # Change user password
username_extract = email_split(email)
user.obj.username = username_extract.local
user_obj.active = is_active
user_obj.staff = is_staff
user_obj.superuser = is_superuser
user_obj.save(self._db)
return user_obj
def create_staffuser(self, email, password=None):
user = self.create_user(
email,
password = password,
is_staff = True
)
return user
def create_superuser(self, email, password=None):
user = self.create_user(
email,
password = password,
is_staff = True,
is_superuser = True
)
return user
class Users(AbstractBaseUser):
name = models.CharField(max_length=255)
email = models.CharField(unique=True, max_length=255)
group = models.ForeignKey('app.Groups', models.DO_NOTHING)
phone = models.CharField(max_length=255, blank=True, null=True)
address = models.CharField(max_length=255, blank=True, null=True)
title = models.CharField(max_length=255, blank=True, null=True)
fax = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
login = models.CharField(unique=True, max_length=255)
crypted_password = models.CharField(max_length=255)
password_salt = models.CharField(max_length=255)
persistence_token = models.CharField(max_length=255)
login_count = models.IntegerField()
failed_login_count = models.IntegerField()
last_request_at = models.DateTimeField(blank=True, null=True)
current_login_at = models.DateTimeField(blank=True, null=True)
last_login = models.DateTimeField(blank=True, null=True)
current_login_ip = models.CharField(max_length=255, blank=True, null=True)
last_login_ip = models.CharField(max_length=255, blank=True, null=True)
time_zone = models.CharField(max_length=255)
preferences = models.TextField(blank=True, null=True)
perishable_token = models.CharField(max_length=255)
USERNAME_FIELD = 'email'
PASSWORD_FIELD = 'crypted_password'
# ## Runs all requests through custom user manager
objects = CardsUserManager()
REQUIRED_FIELDS = []
def __str__(self):
return self
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
@property
def is_staff(self):
return self.is_staff
@property
def is_superuser(self):
return self.is_superuser
@property
def is_active(self):
return self.is_active