pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.

Home Page:https://allauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to prevent django.db.utils.IntegrityError for duplicate social login email?

quroom opened this issue · comments

django.db.utils.IntegrityError: duplicate key value violates unique constraint "account_emailaddress_email_key"

I get this error when I login same only email with another SocialLogin
(like facebook and google email can be duplicate)

ACCOUNT_UNIQUE_EMAIL = False
ACCOUNT_PREVENT_ENUMERATION = False

So I added this option but error still comes
email field is actually not unique.
I am usnig username as unique field for user.

And I haev one more question.
As long as email is not unique, could we create socialaccount has same email?
Or Can we make socialaccount with same user account?

I am not sure how I can implement. It's little bit complext to be because my env has nuxt frontend and django backend. It makes more complext.

I already migrated djang-allauth and then I changed ACCOUNT_UNIQUE_EMAIL to False
That's why error comes. I guess we can add and drop constraint manually.

https://github.com/pennersr/django-allauth/blob/main/allauth/account/migrations/0002_email_max_length.py

PS. I treid this solution. It should be working but I get same error. I don't have any idea why it doen't work as I expected.
#2517 (comment)

If you signup with a social account that has an email address that already exists locally, you are asked to enter a new email address. Not sure why this is not working for you. Are you using plain allauth? Can you reproduce this using the example project, or, the online demo? Are you on the latest version?

If you signup with a social account that has an email address that already exists locally, you are asked to enter a new email address. Not sure why this is not working for you. Are you using plain allauth? Can you reproduce this using the example project, or, the online demo? Are you on the latest version?

I guess it's database level issue :) migration code was not applied correctly. I don't know exact reason why It wasn't applied.
And I don't use latest version. I will make small example and test when I have time :)
Thanks for quick answer 👍