Skip to content

Conversation

@RasmusN
Copy link
Contributor

@RasmusN RasmusN commented May 7, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Adds error code 2601 to be represented as gorm.ErrDuplicatedKey in the error translator.

User Case Description

SQL Server have two slightly different error codes for duplicate key errors: 2627 occurs on unique/PK constraint violations, while 2601 is triggered by unique index violations. Both indicate duplicate keys but stem from different schema definitions.

Description from sqlserver

select * from sysmessages where (error = 2627 or error = 2601) and msglangid = 1033
error severity dlevel description msglangid
2601 14 0 Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls. 1033
2627 14 0 Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'. The duplicate key value is %ls. 1033

SQL Server have two slightly different error codes for duplicate key errors:
2627 occurs on unique/PK constraint violations, while 2601 is triggered by unique index violations.
Both indicate duplicate keys but stem from different schema definitions.
@jinzhu jinzhu merged commit 63b76aa into go-gorm:master May 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants