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

2,510 views
Skip to first unread message

Russell Keith-Magee

unread,
Oct 24, 2012, 12:37:43 AM10/24/12
to django...@googlegroups.com

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 %-)

Stephen Anto

unread,
Oct 24, 2012, 5:51:19 AM10/24/12
to django...@googlegroups.com
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.

On Wed, Oct 24, 2012 at 9:32 AM, 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.

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

--
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

Russell Keith-Magee

unread,
Oct 24, 2012, 5:56:16 AM10/24/12
to django...@googlegroups.com
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 %-)

NoviceSortOf

unread,
Dec 12, 2016, 2:31:19 PM12/12/16
to Django users
I've replaced the use of ForeignKey as mentioned above for models.ForeignKey(settings.AUTH_USER_MODEL).

But I still get the following syncdb errors.
***************************************************************************************************************************
CommandError: One or more models did not validate:
admin.logentry: 'user' has a relation with model books.user, which has either not been installed or is abstract.

auth.user: Model has been swapped out for 'books.user' which has not been installed or is abstract.

registration.registrationprofile: 'user' has a relation with model books.user, 
which has either not been installed or is abstract.
***************************************************************************************************************************

Any advice appreciated.


Reply all
Reply to author
Forward
0 new messages