我有一个 seq 'user_tfa_info_seq',我想在 Gorm 模型的 'user_tfa_info' 表中使用它。
我使用了以下结构,但不起作用。
type UserTfaInfo struct{
ID uint `gorm:"primary_key;type:bigint(20) not null" sql:"nextval('user_tfa_info_seq')"`
}
最近我遇到了类似的问题并设法解决了。 https://gorm.io/docs/models.html#高级
我使用
gorm:"->"
将该字段声明为只读,因此在创建新记录时,其值由数据库的默认值(例如 nextval('user_tfa_info_seq')
)设置。