Dreams of Thought

Are dreams thoughts… or are thoughts dreams..

RSS Feed

ForeignKey to custom user model in Django

Posted by Anirudh on July 16, 2013 at 2:30 PM

Came across this problem when running a syncdb in Django (>=1.5) :

CommandError: One or more models did not validate:
APP.ModelName: 'user' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.

So you define a custom user model and add the appropriate line to the settings.py file. Then you add a ForeignKey from a model in your app the way the Django doc tells you to. And then you see this (the one above) error when you run a syncdb.

We hit upon this problem. The reason this happened was that the AUTH_USER_MODEL setting was below the INSTALLED_APPS in the settings.py file. Django will not handle forward referencing in this case. The solution is to simply move the AUTH_USER_MODEL setting above the INSTALLED_APPS settting.

Filed under django
You can leave a comment, or trackback from your own site.


You can be the first to comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>