FG
๐Ÿ—„๏ธ Databases

.save() is throwing duplicate key value violates unique constraint on Postgresql

Freshabout 4 years ago
Mar 14, 20260 views
No verified fix yetBe the first to submit a fix.

Problem

Issue Description When trying to upsert an entity to a Postgresql DB, I get a `QueryFailedError: duplicate key value violates unique constraint`. Expected Behavior I currently have a simple case : [code block]` Where the User entity is defined as such : [code block]` Actual Behavior [code block]` with a `QueryFailedError: duplicate key value violates unique constraint`. Steps to Reproduce A simple typeorm + Postgresql stack should suffice My Environment I'm on a plain TS stack, nothing fancy atm. Relevant Database Driver(s) - [ ] `aurora-data-api` - [ ] `aurora-data-api-pg` - [ ] `better-sqlite3` - [ ] `cockroachdb` - [ ] `cordova` - [ ] `expo` - [ ] `mongodb` - [ ] `mysql` - [ ] `nativescript` - [ ] `oracle` - [x] `postgres` - [ ] `react-native` - [ ] `sap` - [ ] `sqlite` - [ ] `sqlite-abstract` - [ ] `sqljs` - [ ] `sqlserver` Are you willing to resolve this issue by submitting a Pull Request? - [ ] Yes, I have the time, and I know how to start. - [x] Yes, I have the time, but I don't know how to start. I would need guidance. - [ ] No, I don't have the time, although I believe I could do it if I had the time... - [ ] No, I don't have the time and I wouldn't even know how to start.

Error Output

Error: duplicate key value violates unique constraint`.

0 Fixes

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescriptbugneeds-more-infodriver:-postgresneeds-tests