`Error: Unique constraint failed on the (not available)`
See original GitHub issueNote: Please read https://github.com/prisma/prisma/issues/10829#issuecomment-1065842833 before responding to this issue.
Bug description
PlanetScale/Vitess does not provide the column name. But additionally to that not showing, we are also missing the additional fields or constraint string that is present in the error, helping the user to figure out what might be wrong.
How to reproduce
Cause unique constraint error on PlanetScale/Vitess
Expected behavior
More helpful error message.
Prisma information
Environment & setup
- OS:
- Database:
- Node.js version:
Prisma Version
3.7.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:26
- Comments:27 (5 by maintainers)
Top Results From Across the Web
SQLite3 UNIQUE constraint failed error - Stack Overflow
You get a UNIQUE constraint failed error when the data that you are inserting has an entry which is already in the corresponding...
Read more >SQLite Error: UNIQUE constraint failed - Node-RED Forum
The error says that you are trying to add a record to a table with a value for a field that is defined...
Read more >How To Handle Prisma Unique Constraints with a Friendly Error
Often, your data model will have a unique constraint to prevent duplicate records. ... A Character has to have a unique name. No...
Read more >"UNIQUE constraint failed" error with UPSERT and UPDATE ...
"UNIQUE constraint failed" error with UPSERT and UPDATE trigger that does INSERT OR REPLACE · (1) By Even Rouault (rouault) on 2022-10-16 18:06: ......
Read more >mailmng-outgoing failed: ERROR:__main__:UNIQUE ...
One of the following errors is displayed: PLESK_ERROR: mailmng-outgoing... ... mailmng-outgoing failed: ERROR:__main__:NOT NULL constraint ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Digging more into this seems like when a raw query is executed via PlanetScale, it does return some data about the column on which the unique constraint first fails on.
Here’s an example with a users table with unique
emailanduuid(where theuuidis generated application side)Failing with
emailwhen bothemailanduuidare duplicates:Failing with
uuidwhen onlyuuidis a duplicate:Overall new to the Prisma codebase, but going to start looking into where in Prisma are these errors handled. Any directions would be super helpful.
This issue here is about the error message, which can not provide the actual column name as it is not provided by PlanetScale/Vitess, as described in the original issue. There is no real solution than to fix Vitess or implement some workaround that gets the column name from the original query.
If you have any code that causes the
Unique constraint failed ...error message although it is unexpected, this issue here is not the correct one. Please open a new issue and describe your problem. (E.g. your problem @dyeoman2 would be a good new bug report so we can look into how this can happen)