question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate keys issues

See original GitHub issue

Issue type:

[x] question [x] 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)

Steps to reproduce or a small repository showing the problem:

Hello, I have a minor but important issue, I used Typeorm for a while and everything is very nice but I just complete a project for a client. He added manually some rows on a database [ don’t ask me why ] and now when I save a new entity, Typeorm throw me an exception around a primary key duplicate key value violates unique constraint “xxx_pkey”

The issue is that TypeOrm is trying to set the next id value that he insert “himself”.

For example, I programmatically create 100 entities from id 1 to 100, my client added another 42 entities with id 101… 142. Then, Typeorm try on save to create an entity with the id 101.

How can a fix, configure that ?

Thanks 😃

ps: waaaah an issue with no code 😜

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
4ndt3scommented, Jul 10, 2019

You need to inform postgres the change on the sequence of ids. Go to pgadmin or psql console and find the name of the attached sequence of the id column, then execute:
ALTER SEQUENCE name RESTART 143

0reactions
twigs67commented, Feb 7, 2021

Is this a TypeOrm related issue or PostGres primarily? This seems kind of insane that we have to manage this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reasons for "DUPLICATE KEY" errors? - Stack Overflow
A row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error.
Read more >
Why Your Duplicate Key From a Hardware Store Doesn't Work
It's incorrectly cut. Look at it. · The incorrect blank was used. Keys will typically have a short number on the head. ·...
Read more >
How to Identify a Bad Key Copy: 9 Steps (with Pictures)
1. Do the keys line up side by side? The easiest way to tell if a key is bad is that if it...
Read more >
Hidden dangers of duplicate key violations in PostgreSQL and ...
In this post, we showed you some of the issues that duplicate key violations can cause in a PostgreSQL database. They can cause...
Read more >
What keys can't be duplicated? - Sure Lock & Key
Are there keys that even professional locksmiths can't duplicate? We have the answer! Sure Lock & Key is ready to be your locksmith...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found