FG
💻 Software🗄️ Databases

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

Freshover 5 years ago
Mar 14, 20260 views
Confidence Score77%
77%

Problem

Issue type: [x] question [ ] bug report [ ] feature request [ ] documentation issue Database system/driver: [ ] `cordova` [ ] `mongodb` [ ] `mssql` [ ] `mysql` / `mariadb` [ ] `oracle` [x] `postgres` [ ] `cockroachdb` [ ] `sqlite` [ ] `sqljs` [ ] `react-native` [ ] `expo` TypeORM version: [x] `latest` [ ] `@next` [ ] `0.x.x` (or put your version here) This was working for me earlier but now it is not. I am using a composite key of three different properties. Every time I try to update and existing row, I get the error `QueryFailedError: duplicate key value violates unique constraint "PK_8b1375852f33d30b328388e5a5c"`. This is my entity: [code block]

Error Output

error `QueryFailedError: duplicate key value violates unique constraint "PK_8b1375852f33d30b328388e5a5c"`.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence90% success rate8 verificationsLast verified Mar 14, 2026

Solution: .save() is throwing duplicate key value violates unique constraint

Low Risk

I can confirm that this problem still exists. I'm using `typeorm` with `postgres`.

76

Trust Score

8 verifications

90% success
  1. 1

    I can confirm that this problem still exists. I'm using `typeorm` with `postgres

    I can confirm that this problem still exists. I'm using `typeorm` with `postgres`.

Validation

Resolved in typeorm/typeorm GitHub issue #4122. Community reactions: 64 upvotes.

Verification Summary

Worked: 8
Partial: 1
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescriptquestiondriver:-postgres