go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
88 stars 666 forks source link

feat: insert record with ID assigned doesn't commit the sequence ID #718

Open manish-kharel opened 3 months ago

manish-kharel commented 3 months ago

Explain your user case and expected results

When a record is inserted with an assigned ID using db.Create(), that sequence ID is not committed. Example: Given the sequence ID for user table is at ID: 2. and if I create an entity User {ID: 5, Name: "some user" } with ID 5 assigned, gorm creates the entity. So, when the turn for ID 5 with auto-sequence comes in, pkey violation error occurs.

The expected result would be , that GORM would see ID 5 is already used by another record and use continue from ID 6.