You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you create an entity with primary ID assigned to it, gorm.Create inserts the record but doesn't commit the sequence value. By this, i mean, when the autosequence arrives to the ID you provided at some point, it still will try to use the ID for which a record is already there, resulting in pkey violation error.
Well, the next time you try to create with autosequence, it proceeds to the next value. But, i guess relying on that shouldn't be the case.
It might have implications if you are migrating some records on Startup using db.Create. At some point, those IDs will collide with the one from auto-sequence.
Looking for answers or maybe possible fixes.
Database used: POSTGRES
The text was updated successfully, but these errors were encountered:
If you want to migrate some data, then you can remove the pkid from the code and let him insert it himself. If you have to use pkid, then you need db.update()
Not sure if you understood the issue correctly.
The problem is, gorm is auto-assigning an ID that is already used in the database. This happens if you've previously created a Record, where you assigned the ID yourself. And after, when auto-sequence value arrives to the manually inserted value, it'll still try to use the same value regardless of the fact that the record is already there giving out pkey violation
The problem is, gorm is auto-assigning an ID that is already used in the database.
Gorm will not auto-assigning id
This happens if you've previously created a Record, where you assigned the ID yourself.
Yes, this is the basic functionality of the database, you can specify the id. But gorm will not process the sequence additionally.
In general, Gorm will provide some easy-to-use functions, which have basically the same semantics as the database. But it won't provide magic, as this would make it very different from directly operating the database, thereby increasing the user's learning cost.
GORM Playground Link
go-gorm/playground#718
Description
If you create an entity with primary ID assigned to it, gorm.Create inserts the record but doesn't commit the sequence value. By this, i mean, when the autosequence arrives to the ID you provided at some point, it still will try to use the ID for which a record is already there, resulting in pkey violation error.
Well, the next time you try to create with autosequence, it proceeds to the next value. But, i guess relying on that shouldn't be the case.
It might have implications if you are migrating some records on Startup using db.Create. At some point, those IDs will collide with the one from auto-sequence.
Looking for answers or maybe possible fixes.
Database used: POSTGRES
The text was updated successfully, but these errors were encountered: