Forums

duplicate key value violates unique constraint "auth_user_username_key"

I have been hosting an open source web application using Openstreetmap authentication for several years.

Until last year, OAuth1 authentication was used, but Openstreetmap discontinued OAuth1 authentication and switched to Oauth2 authentication.

In the web application database, there are data tables with the user name "SanSaaan" that were created using OAuth1 authentication.

On the Openstreetmap site, I registered an Oauth2 authentication application with the username "SanSaaan" and switched to Oauth2 authentication for the web application. https://www.openstreetmap.org/oauth2/applications/

Then I got the following exception error when I logged into the web application.

In fact, the database contains a data table for the user "SanSaaan" that was created during the OAuth1 authentication.

I want to update the data tables previously created with "SanSaaan" using Oauth2 authentication.

When I change my username to "SanSaaan LLC" on Openstreetmap site, the authentication is successful and I can create a new data table. but I have trouble updating the data I created in "SanSaaan".

Do you have any idea how to update the previously created data tables in "SanSaaan" using Oauth2 authentication?

=== Exception Error =========================================================================
IntegrityError at /complete/openstreetmap-oauth2/

duplicate key value violates unique constraint "auth_user_username_key"
DETAIL:  Key (username)=(SanSaaan) already exists.

Request Method:     GET
Request URL:    https://sansaaan.pythonanywhere.com/complete/openstreetmap-oauth2/?redirect_state=rDF9FiqiBw4KK0KGpfilSkB6iSmqyAql&code=Ga-xfRNdjTyrLV1fVcXVoScZ8fr5_OlL_Hd1FAhfIZk&state=rDF9FiqiBw4KK0KGpfilSkB6iSmqyAql
Django Version:     2.2.17
Exception Type:     IntegrityError
Exception Value:

duplicate key value violates unique constraint "auth_user_username_key"
DETAIL:  Key (username)=(SanSaaan) already exists.

Exception Location:     /home/sansaaan/vmap/lib/python3.8/site-packages/django/db/backends/utils.py in _execute, line 84
Python Executable:  /usr/local/bin/uwsgi
Python Version:     3.8.10
Python Path:

['/home/sansaaan/vmap/lib/python3.8/site-packages/umap',
 '/var/www',
 '.',
 '',
 '/var/www',
 '/home/sansaaan/vmap/lib/python38.zip',
 '/home/sansaaan/vmap/lib/python3.8',
 '/home/sansaaan/vmap/lib/python3.8/lib-dynload',
 '/usr/lib/python3.8',
 '/home/sansaaan/vmap/lib/python3.8/site-packages',
 '/home/sansaaan/vtm/vtm',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/local/lib/python2.7/dist-packages']
============================================================================

If I understand correctly you should be able to update it in your django admin in the browser or in the django shell in the console.

Hi fjl. Thank you for your fast reply. Please let me know the procedure of updating it in your django admin in the browse.

It's hard to give you detailed instructions as we know nothing about your app.

Thank you, fjl. It seems hard to fix the problem.

Glad you got it working