🗄️Tried to save a value that already exists (duplicate)
duplicate key value violates unique constraint "users_email_key"
A value that should exist only once (like an email) is already saved, and the same value was saved again.
🤔 Why does it happen?
- Someone tried to sign up twice with the same email
- The button was pressed twice, so the same request went out twice
🔧 Try this
- Check whether it already exists before saving, or change it to update if it exists (upsert)
- Disable the button for a moment after it's pressed
🤖 Ask your AI like this
I get 'duplicate key value violates unique constraint' when saving. Please fix it so that when the value already exists, it tells the user or overwrites it (upsert), and make sure it only saves once even if the button is pressed twice. [Paste the full error here]
Replace the [ ] parts with your own situation, and paste the error with a few extra lines before and after it.
Related terms
Other errors in this group
- Database connection failed
Can't reach database server - Table doesn't exist
relation "…" does not exist - Login address mismatch (redirect_uri_mismatch)
Error 400: redirect_uri_mismatch - Blocked by security rules (RLS), so it won't save
new row violates row-level security policy - Login info has expired (JWT)
JWT expired - Login app info is wrong (invalid_client)
Error 401: invalid_client - Google login blocked (app not verified, testing mode)
Access blocked: app has not completed the Google verification process - Prisma isn't ready (prisma generate)
@prisma/client did not initialize yet. Please run "prisma generate"