hretic hretic - 1 year ago 87
Python Question

Changing default auth_user table name

i'm happy with django built in user/auth , i just want to add some fields to it and change table name (mostly the last one , i can use another table for custom fields )

so i searched around and apparently we can use subclass as suggested on Rename Django's auth_user table?

So i have to start a new app and use it's model to as a subclass for

or there is another way? (After all i just want to use it's model and other parts of app are useless )

anyway i created a new project / started app called
and in its model i have this code


from django.db import models

from django.contrib.auth.models import AbstractUser
class customuser(AbstractUser):

class Meta:
swappable = 'AUTH_USER_MODEL'
db_table = 'customuser'

i ran makemigrations AND migrate ... it's done successfully

enter image description here

but atill the tables with default name was created in database as you can see below ... am i missing something ?

enter image description here

Answer Source

To use a custom user model, you need to set the AUTH_USER_MODEL setting in your settings module.

Note that you don't need to set swappable = 'AUTH_USER_MODEL'. This is an undocumented and private attribute, and is probably better left untouched.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download