[ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work

Showing 1-5 of 5 messages
[ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work Surya Mukherjee 10/23/12 9:02 PM
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.

django_openid_auth is a third party OpenID library, but the first two are pure Django and they're still breaking. Wat do?

Re: [ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work Russell Keith-Magee 10/23/12 9:39 PM

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 %-)
Re: [ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work Stephen Anto 10/24/12 2:51 AM
Hi,

You can extend Default Django User model without breaking its architecture. Just visit http://www.f2finterview.com/web/Django/21/ It will explain you in detail.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/fLbSAxq1RysJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Re: [ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work Russell Keith-Magee 10/24/12 2:57 AM

On Wed, Oct 24, 2012 at 5:51 PM, Stephen Anto <charvi...@gmail.com> wrote:
Hi,

You can extend Default Django User model without breaking its architecture. Just visit http://www.f2finterview.com/web/Django/21/ It will explain you in detail.

If you're going to give advice, it's probably a good idea to check that your advice is current.

The approach that the original poster has suggested is in no way "breaking the architecture" of Django - it's one of the new features in Django 1.5. 

As a side effect of the changes introduced in 1.5, the API you've suggested (AUTH_PROFILE_MODULE) has been deprecated. It will raise warnings if used in Django 1.5 and 1.6, and be removed completely in Django 1.7. 

Yours,
Russ Magee %-)
Re: [ver. 1.5] Specifying custom User model (extends AbstractUser) doesn't work Lewis Taylor 3/21/13 4:48 AM
And this is why I learnt the names of many of those major in the Django community! Now if I post after them, it's mostly to say..... Yes I agree.

Like I'm doing now :-)