Add unique key support for save()
See original GitHub issueIssue type:
[ ] question [ ] bug report [x] 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)
Hello.
I have entity with unique field. I am trying to save passing this unique key. After 2nd save call, I get “duplicate key”, beacuse typeorm is inserting instead of updating, beacuse typeorm does not check for unique key, but primary key.
Unique key should be considered in save, when primary key is not provided.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How add unique key to existing table (with non uniques rows)
You can do as yAnTar advised. ALTER TABLE TABLE_NAME ADD Id INT AUTO_INCREMENT PRIMARY KEY. OR. You can add a constraint
Read more >Create Unique Constraints - SQL Server - Microsoft Learn
In the grid under General, select Type and choose Unique Key from the drop-down list box to the right of the property, and...
Read more >How to make a column unique in SQL? - LearnSQL.com
First we write ALTER TABLE, then we list the name of the table (in our example: product ), and next we add the...
Read more >Difference between Unique Indexes and Unique Constraints ...
This article explores the difference between Unique Indexes and Unique Constraints in SQL Server.
Read more >Defining Unique Constraints in JPA - Baeldung
A composite unique key is a unique key made up of a combination of columns. To define a composite unique key, we can...
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 FreeTop 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
Top GitHub Comments
Also wondering, any progress yet?
The upsert is done by using columns that identify the data, the primary key. As I know a constraint “Unique key” have not for purpose to identify a row on your table. If it’s the case that mean your column have to be include on your primary key.
To apply an upsert like you expect using the fact that there is a conflict is not a common case and should be handle differently than using
Save
.