[Django]-Duplicate key value violates unique constraint while saving ModelForm

2👍

The idea of having a separate table users_userprofile is probably to allow multiple entries for a single user.

(Else, if there can only be a single attribute rewardpoints per user, you would just add the column to the table auth_user and drop the table users_userprofile.)

The actual implementation contradicts this idea. You have a UNIQUE constraint on users_userprofile.user_id, which does not make sense:

"users_userprofile_user_id_key" UNIQUE CONSTRAINT, btree (user_id)

It causes the error and should probably be removed.

Leave a comment