Skip to content

Instantly share code, notes, and snippets.

@ZeroCoolHacker
Created March 7, 2022 05:59
Show Gist options
  • Save ZeroCoolHacker/dc3f3688cd2d9efc92c1553456715dbd to your computer and use it in GitHub Desktop.
Save ZeroCoolHacker/dc3f3688cd2d9efc92c1553456715dbd to your computer and use it in GitHub Desktop.
Change from defualt auth model to custom auth model mid project django
# Instructions taken from https://www.caktusgroup.com/blog/2019/04/26/how-switch-custom-django-user-model-mid-project/
1. Create your new app
> python manage.py startapp users
2. Change all User references to get_user_model() and settings.AUTH_USER_MODEL
2. set db_table of your user model to auth_user
```
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
class Meta:
db_table = 'auth_user'
```
3. Run these postgres queries
```
INSERT INTO django_migrations (app, name, applied) VALUES ('users', '0001_initial', CURRENT_TIMESTAMP);
UPDATE django_content_type SET app_label = 'users' WHERE app_label = 'auth' and model = 'user';
You're Good to go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment