Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove existing fields in the default User DB in Django?

I have created and AbstractUser with some fields that I want the User Class to have. But after successfully creating a new User Model, the user table now has the previous columns (the ones which would have been added on migration of the default User Model) and also has the columns which I have added in the Custom User Model.

Is there a way to remove the columns which are added by default?

Here's my models.py

class CustomUser(AbstractUser):
    ''' SOME UNIQUE FIELDS '''
    class Meta:
        swappable = 'AUTH_USER_MODEL'
        db_table = 'users'

These are the fields that appear even without specifying in the model. How can I get rid of them?

enter image description here

like image 773
Yashit Avatar asked Dec 04 '25 18:12

Yashit


1 Answers

As you are extending the model AbstractUser, it has all the fields of that class, https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#extending-django-s-default-user.

If you want a complete custom user, you should extend AbstractBaseUser. https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#specifying-a-custom-user-model.

like image 177
schrodigerscatcuriosity Avatar answered Dec 07 '25 14:12

schrodigerscatcuriosity