Why am I getting this page and how do I solve it?


"""Django admin customization"""

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.utils.translation import gettext_lazy as _
from .models import User

# Register your models here.

class UserAdmin(BaseUserAdmin):
    """Define the admin page for users."""
    ordering = ["id"]
    list_display = ['email', 'name']
    fieldsets = (
        (None, {'fields':('email', 'password')}),
            _('Permission'), {'fields':('is_active', 'is_staff', 'is_superuser')}
        (_('Important Dates'), {'fields':('last_login',)})
    readonly_fields = ['last_login']
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': (

admin.site.register(User, UserAdmin)


"""Database models"""

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

# Create your models here.

class UserManager(BaseUserManager):
    """Manager for users."""

    def create_user(self, email, password=None, **extra_fields):
        """Create, save and return a new user."""
        if not email:
            raise ValueError("User must have an email address.")
        user = self.model(email=self.normalize_email(email), **extra_fields)

        return user
    def create_superuser(self, email, password=None):
        user = self.create_user(email, password)
        user.is_staff = True
        user.is_superuser = True

        return user

class User(AbstractBaseUser, PermissionsMixin):
    """User in the system"""
    email = models.EmailField(max_length=255, unique=True)
    name = models.CharField(max_length=255)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'email'

This may or may not be directly related to this particular error, you do have a mistake in your User model definition.

You have:

Mixin classes must appear before the base class in a model class definition.

If this is not the solution to the problem, we’ll need to know more details about when you’re getting this error. What were you doing or clicked on, to cause this error to appear?

@ KenWhitesell
This is the page. I clicked Save at the right bottom.

Did you fix your model definition? If so, what was the result?

Yes, I fixed it. But the result was exactly the same.

Did you delete any entries in User?

No, I did not delete any entry.

Something has messed up your database then.

Depending upon how much data you’re concerned about in the database, you might just want to drop it and recreate it.

Otherwise, you can use your database tools to empty the django_admin_log table.

I am doing this in a docker django project, so please tell me how to do this. I have no idea how to recreate the database and if I recreated the database, will my superuser gets deleted too?

yes it will also deleted