Keycloak & Django Setup Error - "UNIQUE constraint failed: auth_user.username" & usernames are being hashed

386 views
Skip to first unread message

Ammon Quackenbush

unread,
Oct 5, 2021, 4:37:20 PM10/5/21
to Django users

I am setting up keycloak for a django project and this is the error I receive:


IntegrityError at /oidccallback/UNIQUE constraint failed: auth_user.usernameRequest Method:
GET

It looks like when I log in, keycloak tries to create my user again, even though my user is in the database.

Also, my usernames are hashed in the auth_user table in the database.

This is my code in my settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

I also tried setting the OIDC_CREATE_USER setting to False but that only prevented django from from detecting login sessions (which still were created properly).

Any ideas on what is going wrong and how I can fix it?

DJANGO DEVELOPER

unread,
Oct 6, 2021, 1:26:24 AM10/6/21
to django...@googlegroups.com
you're facing this error because django receives nique usernames. so you are not allowed to create another username with the same username.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6be23087-ab54-4bfb-8a57-1bc8fbe35359n%40googlegroups.com.

Adeyemi Deji

unread,
Oct 6, 2021, 4:59:33 AM10/6/21
to Django users
Hi, can you make a snapshot of your models.py file?

Ammon Quackenbush

unread,
Oct 7, 2021, 5:53:45 PM10/7/21
to Django users
I was able to solve this problem by removing commas from the end of lines from my models in models.py.
Reply all
Reply to author
Forward
0 new messages