# Delete the django admin logs model

**URL:** <https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028>\
**Category:** Getting Started\
**Created:** [December 9, 2023, 12:48pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028 "2023-12-09T12:48:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 9, 2023, 12:48pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/1 "2023-12-09T12:48:51Z")

</div>

Hi,

I have created a new user authentication system using DRF. As part of this implementation, I have to run migrations that error because the `django_admin_logs` model already exists.

Other than losing the historic data, is it safe to delete and recreate from the new migration?

I’ve done this in dev and seems to be fine, but wasn’t sure if this is model is linked to anything else?

Thanks

---

<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:** [December 9, 2023, 2:59pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/2 "2023-12-09T14:59:10Z")

</div>

Is this a case where you’re changing the User model after the project has been started?

If so, see [Changing to a custom User model mid-project](https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#changing-to-a-custom-user-model-mid-project)

If not, what has happened to put you in this situation? (I don’t see how this can happen in the normal routine.)

What I’m wondering is, if because of the situation you have found yourself in, is whether there are other hidden “gotchas” that you haven’t encountered yet as a result.

---

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 9, 2023, 4:06pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/3 "2023-12-09T16:06:01Z")

</div>

Hi Ken,

To be honest im not sure im doing the right thing, but i am building more APIs and these are being called from a React frontend.

I’ve been looking at different ways to do this and it look like using `JWT` with `Djoser` and `DRF` was a good approach.

I’ve created this class

```auto
class UserAccount(AbstractUser, PermissionsMixin):
    email = models.EmailField(unique=True)
    username = models.CharField(max_length=40, unique=True)
    first_name = models.CharField(max_length=40)
    last_name = models.CharField(max_length=40)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)

    objects = UserAccountManager()
    groups = models.ManyToManyField(Group, blank=True, related_name='user_accounts')

    user_permissions = models.ManyToManyField(
        Permission,
        blank=True,
        related_name='user_accounts'
    )
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'first_name', 'last_name']

    def get_full_name(self):
        return f"{self.first_name} {self.last_name}"

    def get_short_name(self):
        return self.first_name
    
    def __str__ (self):
        return self.email

```

But when I run the migration I get the error about migration dependency and the `django_admin_logs`

Also, the app doesn’t contain data from the user side that I need to keep so didn’t seem like a big deal.

I’ve also added `AUTH_USER_MODEL = 'accounts.UserAccount'` because I’ve moved the authentication into its own app within the project. Is this a bad idea?

---

<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:** [December 9, 2023, 5:13pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/4 "2023-12-09T17:13:26Z")

</div>

My previous question still applies - are you trying to create a new User model “mid-project”?

If so, the _easiest_ thing to do is drop your database, delete all your migrations, run the initial migration, do makemigration, then migrate.

There are issues involved with switching User models mid-project that go beyond just the migration issue with the admin log model. See the docs referenced above.

---

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 9, 2023, 5:22pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/5 "2023-12-09T17:22:47Z")

</div>

Ok, sorry. I’m not necessarily looking to create a new user model. I want to add some additional fields and also set the login to email rather than username.

I’m assuming the default auth model would be fine to work with DFR and JWT, i just thought if it was straightforward it would be a cleaner way to go?

I understand that dropping the database would delete everything and then would need a way to restore it, but in the past using fixtures took forever to complete.

So i think i will need to see if i can modify the existing user model

---

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 9, 2023, 6:05pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/6 "2023-12-09T18:05:17Z")

</div>

Ignore all of this, i just switched back to using the original auth/usermodel and it’s looks fine.

---

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 10, 2023, 9:10am UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/7 "2023-12-10T09:10:55Z")

</div>

Sorry, Ken.

Would you just clarify something for me, please?

If I stick with the existing user model which i think is `auth_user` and just add this:

```auto
from django.contrib.auth.models import AbstractUser, BaseUserManager, PermissionsMixin, Group, Permission

class UserAccount(AbstractUser, PermissionsMixin):
    email = models.EmailField(unique=True)
    username = models.CharField(max_length=40, unique=True)
    first_name = models.CharField(max_length=40)
    last_name = models.CharField(max_length=40)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now_add=True)

    objects = UserAccountManager()
    groups = models.ManyToManyField(Group, blank=True, related_name='user_accounts')

    user_permissions = models.ManyToManyField(
        Permission,
        blank=True,
        related_name='user_accounts'
    )
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'first_name', 'last_name']

    def get_full_name(self):
        return f"{self.first_name} {self.last_name}"

    def get_short_name(self):
        return self.first_name
    
    def __str__ (self):
        return self.email

```

Which allows me to set the email as the login etc. And then within my `settings.py` I add:

```auto
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = 'backend.UserAccount'

```

backend being my primary app within my project.

Is this going to be ok? Or whatever I do to make the login `email_address` will require me to do some manual data restores etc?

The structure of my project is:

```auto
app_backend
 -settings.py
backend
 -models.py
 -views.py
 -admin.py
...

```

So I’m just a bit confused if using

```auto
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = 'backend.UserAccount'

```

is this correct, or i should be using

```auto
## AUTHENTICATION SETTINGS ##
AUTH_USER_MODEL = app_backend.UserAccount'

```

and moving the model into `app_backend` and creating a new models.py?

Hope this makes sense.

---

<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:** [December 10, 2023, 1:22pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/8 "2023-12-10T13:22:05Z")

</div>

When you do this:

> [@TommyQuality](#):
>
> And then within my `settings.py` I add:
> 
> ```auto
> ## AUTHENTICATION SETTINGS ##
> AUTH_USER_MODEL = ...
> 
> ```

You are no longer doing this:

> [@TommyQuality](#):
>
> If I stick with the existing user model which i think is `auth_user` …

Please read [Substituting a custom User model](https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#substituting-a-custom-user-model) and [AUTH\_USER\_MODEL](https://docs.djangoproject.com/en/5.0/ref/settings/#auth-user-model)

---

<div class="post-metadata">

**Author:** ![TommyQuality](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tommyquality/32/6302_2.png) [@TommyQuality](https://forum.djangoproject.com/u/TommyQuality)\
**Post date:** [December 10, 2023, 1:32pm UTC](https://forum.djangoproject.com/t/delete-the-django-admin-logs-model/26028/9 "2023-12-10T13:32:25Z")

</div>

Thanks, Ken.

I think I need to stick with the username as the authentication for logging in then. ☹
