I am using Cognito to authenticate users on the sign-up and once a user click create an account it should be directed to the verification screen(number and email) but instead I user is facing this error
duplicate key value violates unique constraint "core_user_phone_number_client_key" DETAIL: Key (phone_number, clientid)=(b9e507949695) already exists.
I am not quite sure if this error is related only to Cognito or to the database (Postgres) as I can't see the record on the table but when I try to create an account with the same rejected email is says user already exist but when to try to sign up its say user does not exist( its so tricky)
CodePudding user response:
That certainly looks like a PostgreSQL error, except the part where the key has two columns, but the data only shows one column.
What would usually cause this error is that one transaction tries to insert the same data twice, and so conflicts with itself. Since the transaction rolls back, both rows are gone. So an outside observer can never spot the offending data as it never exists in a committed (visible) form.
CodePudding user response:
from a colleague, so this will solve the issue
operations = [
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_username_key ON core_user (username);'),
# Make sure we take into account related client's id for unique index, to limit uniqueness
# verification by client profiles set (several clients may have profiles with the same email & phone number)
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_email_client_key '
'ON core_user (email, client_id) WHERE is_active = TRUE;'),
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_phone_number_client_key '
'ON core_user (phone_number, client_id) WHERE is_active = TRUE;')
]