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
For integer primary keys, gorm:"primaryKey" should behave like gorm:"primaryKey;autoIncrement:false" instead of gorm:"primaryKey;autoIncrement:true".
Motivation
The default behaviour for gorm.Model is soft deletion. As soft deleted records persist, there's no need for AUTOINCREMENT use as in this case no key values are deleted and thus cannot be reused.
When a record gets deleted with Unscoped, AUTOINCREMENT prevents reuse of the record's ROWID for future records, this may or may not be desired depending on a particular use case.
Given the above, I think changing the default behaviour of gorm:"primaryKey" would be beneficial as the use of AUTOINCREMENT is unnecessary in most cases.
Related Issues
The text was updated successfully, but these errors were encountered:
Describe the feature
For integer primary keys,
gorm:"primaryKey"
should behave likegorm:"primaryKey;autoIncrement:false"
instead ofgorm:"primaryKey;autoIncrement:true"
.Motivation
gorm.Model
is soft deletion. As soft deleted records persist, there's no need forAUTOINCREMENT
use as in this case no key values are deleted and thus cannot be reused.Unscoped
,AUTOINCREMENT
prevents reuse of the record'sROWID
for future records, this may or may not be desired depending on a particular use case.AUTOINCREMENT
is discouraged by SQLite creators due to its performance overhead.Given the above, I think changing the default behaviour of
gorm:"primaryKey"
would be beneficial as the use ofAUTOINCREMENT
is unnecessary in most cases.Related Issues
The text was updated successfully, but these errors were encountered: