Custom User Model (AbstractUser class)

I created a custom user model using the AbstractUser class, without including either the password or usable_password field. However, I encountered the following error in the admin panel when I try to add a new user;
FieldError at /admin/accounts/customuser/add/
Unknown field(s) (usable_password) specified for CustomUser. Check fields/fieldsets/exclude attributes of class CustomUserAdmin.

After investigation, I discovered that the culprit — usable_password — had been automatically added to the default ‘UserAdmin’ class.

This leads me to the following questions:

  1. Why does my CustomUser model appear to inherit the usable_password field?
  2. Why does the AbstractUser/AbstractBaseUser class include usable_password, even though it is not a legitimate model field?
  3. Why is the UserAdmin class attempting to register the default User model, even though my CustomUserAdmin class explicitly defines the fields as:
class CustomUserAdmin(UserAdmin):
    add_form = CustomUserCreationForm
    form = CustomUserChangeForm
    model = CustomUser
    list_display = ["username", "email", "is_staff", "age"]
    fieldsets = UserAdmin.fieldsets + ((None, {"fields": ("age",)}),)
    add_fieldsets = UserAdmin.add_fieldsets + ((None, {"fields": ("age",)}),)

admin.site.register(CustomUser, CustomUserAdmin)

Show the code for your custom user - please format code correctly with ``` on a line before and after the code.

Also show the value of AUTH_USER_MODEL from your settings.py

Welcome @Lanuel !

See the threads at

Thanks for the heads-up on how to properly format a code. Here is the code for custom user:

from django.db import models
from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
    age = models.PositiveIntegerField(null=True, blank=True)

From settings:

AUTH_USER_MODEL = "accounts.CustomUser"

Thank you, I’ll take a look.