feat: insert record with ID assigned doesn't commit the sequence ID #718
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.