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

**URL:** <https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017>\
**Category:** The Admin\
**Created:** [July 2, 2023, 4:44am UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017 "2023-07-02T04:44:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateekkumaroriginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/prateekkumaroriginal/32/17701_2.png) [@prateekkumaroriginal](https://forum.djangoproject.com/u/prateekkumaroriginal)\
**Post date:** [July 2, 2023, 4:44am UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/1 "2023-07-02T04:44:13Z")

</div>

admin.py:-

```auto
"""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': (
                'email',
                'password1',
                'password2',
                'name',
                'is_active',
                'is_staff',
                'is_superuser'
            )
        }),
    )

admin.site.register(User, UserAdmin)

```

models.py:-

```auto
"""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)
        user.set_password(password)
        user.save(using=self._db)

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

        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'

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/d/d30007205cb61dfe595184b5fab41a88b5dea181.png)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 2, 2023, 5:03am UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/2 "2023-07-02T05:03:09Z")

</div>

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

You have:

> [@prateekkumaroriginal](#):
>
> `class User(AbstractBaseUser, PermissionsMixin):`

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?

---

<div class="post-metadata">

**Author:** ![prateekkumaroriginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/prateekkumaroriginal/32/17701_2.png) [@prateekkumaroriginal](https://forum.djangoproject.com/u/prateekkumaroriginal)\
**Post date:** [July 2, 2023, 5:43am UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/3 "2023-07-02T05:43:28Z")

</div>

@ [KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)  
This is the page. I clicked `Save` at the right bottom.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/0/0aa90a3bd4780714aac96336af0f4966ad1a3e3d.png)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 2, 2023, 1:08pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/4 "2023-07-02T13:08:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prateekkumaroriginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/prateekkumaroriginal/32/17701_2.png) [@prateekkumaroriginal](https://forum.djangoproject.com/u/prateekkumaroriginal)\
**Post date:** [July 2, 2023, 1:28pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/5 "2023-07-02T13:28:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 2, 2023, 1:44pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/6 "2023-07-02T13:44:45Z")

</div>

Did you delete any entries in `User`?

---

<div class="post-metadata">

**Author:** ![prateekkumaroriginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/prateekkumaroriginal/32/17701_2.png) [@prateekkumaroriginal](https://forum.djangoproject.com/u/prateekkumaroriginal)\
**Post date:** [July 2, 2023, 2:09pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/7 "2023-07-02T14:09:04Z")

</div>

No, I did not delete any entry.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 2, 2023, 2:17pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/8 "2023-07-02T14:17:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prateekkumaroriginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/prateekkumaroriginal/32/17701_2.png) [@prateekkumaroriginal](https://forum.djangoproject.com/u/prateekkumaroriginal)\
**Post date:** [July 2, 2023, 4:27pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/9 "2023-07-02T16:27:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![immodded](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/immodded/32/14578_2.png) [@immodded](https://forum.djangoproject.com/u/immodded)\
**Post date:** [July 2, 2023, 4:31pm UTC](https://forum.djangoproject.com/t/why-am-i-getting-this-page-and-how-do-i-solve-it/22017/10 "2023-07-02T16:31:04Z")

</div>

yes it will also deleted
