Duplicate keys issues
See original GitHub issueIssue 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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
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
Is this a TypeOrm related issue or PostGres primarily? This seems kind of insane that we have to manage this.