ForeignKey to custom user model in Django

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.

share -