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
Upgrading from gorm v1.22.5 columns of type serial does not appear to increment appropriately. According to the logs, with the new version of gorm and the gorm postgres driver, 0 is inserted in the serial column as opposed to the previous version where nothing is inserted and the column default sequence is correctly used.
Figured it out on my end, if anyone else happens to land on this issue. This is specific to Postgres, not Gorm.
I had this same issue. It happened because I had inserted other records previously and passed an ID explicitly (for seeding fixtures). If you do this, Postgres will not update the sequential IDs and will attempt to create an ID where it left off. You'll notice that if you keep trying the same insert, it will eventually work as Postgres keeps calling next_val on your erroneous queries until it hits an ID that is not taken.
See this SO question for more info. Hope that helps some other poor soul.
GORM Playground Link
go-gorm/playground#439
Description
Upgrading from gorm v1.22.5 columns of type
serial
does not appear to increment appropriately. According to the logs, with the new version of gorm and the gorm postgres driver, 0 is inserted in the serial column as opposed to the previous version where nothing is inserted and the column default sequence is correctly used.gorm v1.3.0, postgress driver v1.3.0:
INSERT INTO "tests" ("id","created_at","updated_at","deleted_at") VALUES (0,'2022-02-22 12:52:02.765','2022-02-22 12:52:02.765',NULL)
gorm v1.22.5, postgress driver v1.2.3:
INSERT INTO "tests" ("created_at","updated_at","deleted_at") VALUES ('2022-02-22 12:51:00.618','2022-02-22 12:51:00.618',NULL) RETURNING "id"
The text was updated successfully, but these errors were encountered: