[Django]-How to properly extend django User model

8👍

What you’re doing right now, is creating a subclass of User, which is non-abstract. This means creating a table that has a ForeignKey called user_ptr pointing at the primary key on the auth.User table. However, what you’re also doing by setting AUTH_USER_MODEL is telling django.contrib.auth not to create that table, because you’ll be using MyUser instead. Django is understandably a little confused 😛

What you need to do instead is inherit either from AbstractUser or AbstractBaseUser.

  • Use AbstractUser if you want everything that User has already, and just want to add more fields
  • Use AbstractBaseUser if you want to start from a clean state, and only inherit generic functions on the User, but implement your own fields.

REF:

👤Thomas

Leave a comment