Reputation: 13376
I have a Django 1.5 app that currently has 2 different models for every user: the built-in User
model, and my own MyUser
model which contains information that is also used in the authentication process.
I would like to merge these two models into one, or at least reference one from the other.
If I was to build a new app, I would do AUTH_USER_MODEL = 'myapp.MyUser'
, but according to the docs, changing the user model makes many changes to the DB and might be difficult to migrate in an existing app.
On the other end, the docs also say that a referenced profile model should only store non-auth related information about a site user
.
So my question is: in an existing app, what is the preferred way to merge my custom user model with the built-in User
model?
Upvotes: 1
Views: 682
Reputation: 165242
Migrating AUTH_PROFILE_MODULE
isn't trivial, but definitely possible:
See http://www.caktusgroup.com/blog/2013/08/07/migrating-custom-user-model-django/ for a detailed walkthrough of the process.
If you are willing to take the time to do this now, it can be a significant step in decreasing technical debt in your project.
Upvotes: 2
Reputation: 51978
I will suggest to use one-to-one relation in django. The model can be like:
class CustomUser(models.Model):
dj_user= models.OneToOneField(User)
Upvotes: 0