Django custom user model in admin, relation “auth_user” does not exist

By | June 8, 2013

I have a custom user model as below:

And using the builtin UserAdmin

While editing the user record works fine, but when I add a user, I get the following error

After some digging around and found this https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms

The culprit is a function clean_uesrname inside UserCreationForm inside django.contrib.auth.forms.py
A few tickets have been created, but apparently the maintainers don’t think it’s a defect

https://code.djangoproject.com/ticket/20188
https://code.djangoproject.com/ticket/20086

def clean_username(self):
# Since User.username is unique, this check is redundant,
# but it sets a nicer error message than the ORM. See #13147.
username = self.cleaned_data[“username”]
try:
User._default_manager.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages[‘duplicate_username’])
The User in this file is directly referencing to the builtin user model.

To fix it, I created my custom forms

6 thoughts on “Django custom user model in admin, relation “auth_user” does not exist

  1. dvc

    Hi James, I’m not using a custom user model. I’m still getting this error. Do you have a clue as to why that could be?

    Reply
    1. James Lin Post author

      Sorry I cannot think of any obvious reason on top of my mind, you will have to show your code to see what might cause it, have you tried stackoverflow?

      Reply
    1. nik

      @dvc, what was the solution? I’m also getting this error without using a custom

      Reply
  2. nik

    @dvc, what was the solution? I’m also getting this error without using a custom user model.

    Reply

Leave a Reply

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