On Wed, Oct 24, 2012 at 12:02 PM, Surya Mukherjee
<lords...@gmail.com> wrote:
Django's standard User class isn't sufficient for my needs so I am making my own User class. As per the User Authentication doc page, I am subclassing AbstractUser (not AbstractBaseUser) to add some new stuff.
____
from django.contrib.auth.models import AbstractUser
class MyUser(AbstractUser):
test = 'Hello world'
____
Pretty simple so far. In settings.py:
____
# Specifies SDBUser as the custom User class for Django to use
AUTH_USER_MODEL = 'app.MyUser'
____
But when i try to syncdb, everything breaks:
[root@Surya project]# manage syncdb
CommandError: One or more models did not validate:
app.userprofile: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
auth.user: Model has been swapped out for 'app.SDBUser' which has not been installed or is abstract.
django_openid_auth.useropenid: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
These error messages are telling you the exact problem. The first and third errors indicate that you have two models causing problems -- a UserProfile in an app called "app", and an UserOpenID model in "django_openid_auth". These models both contain a ForeignKey to User, defined as:
user = models.ForeignKey(User)
This needs to be updated to point at
user = models.ForeignKey(settings.AUTH_USER_MODEL)
As the error message says -- you need to update the relation to point at settings.AUTH_USER_MODEL.
The second error ("Model has been swapped out…") is a side effect of the fact that you're directly referencing the User model. Once you change the ForieignKey references, this third error will go away.
django_openid_auth is a third party OpenID library, but the first two are pure Django and they're still breaking. Wat do?
We've done everything we can to ensure a smooth transition to the new User model, but it can't be completely transparent. App writers will need to update their apps to be 1.5 compatible. Essentially, a Django 1.4 app won't be 100% compatible with Django 1.5 if it contains a hard-coded foreign key reference to User.
This is discussed both in the release notes [1], and in the documentation of the swappable User feature [2].
Yours,
Russ Magee %-)