Rename my Django auth app to fix the "Application labels aren't unique" error

When I created my Django project I created an app called auth. I never used django.contrib.auth, instead I rolled my own authentication code. A User model without a password field, custom API views and serializes, login goes via magic links sent to email, etc. I didn't use the Django Admin so I never needed Django's auth implementation.

Now I do want to add the Django Admin to my project, and for that I need to add django.contrib.auth and now I am running into some big problems because of the error django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: auth.

Renaming my own auth app doesn't seem possible. I tried to change the label in its AppConfig but existing migrations are breaking in all sorts of fun and exiting ways. So I thought I'd import Django's auth app with a custom label, like so:

# djangoauth.py
from django.apps import AppConfig


class DjangoAuthConfig(AppConfig):
    name = "django.contrib.auth"
    label = "django_auth"

And then I added djangoauth.DjangoAuthConfig to INSTALLED_APPS. But that also doesn't work, as Django's auth app has migrations with the auth name being hardcoded, so changing the app label now breaks those migrations.

I don't really know how to fix this problem. I really wish Django would deal with duplicate app names (just prefix one of them, like django_contrib_auth) but yeah that's not the case. So how can I rename one of these auth apps so that I can use both of them? Without the risk of loosing existing auth data? My app has plenty of users and I really can't have that table be dropped/recreated.

Yes, I have seen How to change the name of a Django app?, but it's an answer from 2011 and I am really hoping that the situation has improved since then 😬

Back to Top