表结构如下,DeviceID 是主键整数字段,但是不是自增类型
type SensorCurrent struct {
DeviceID uint json:"device_id" gorm:"primaryKey;column:Device_ID"
SampTime time.Time json:"sampTime" gorm:"column:SampTime_DT"
AlmLevelID uint json:"almLevelID" gorm:"column:AlmLevel_ID;default:0"
}
赋值插入成功,database.DbCtx.Db.Error = nil,但是查询数据库没有任何记录
修改DeviceID的tag如下,去掉tag里的Primarykey
type SensorCurrent struct {
DeviceID uint json:"device_id" gorm:"column:Device_ID"
SampTime time.Time json:"sampTime" gorm:"column:SampTime_DT"
AlmLevelID uint json:"almLevelID" gorm:"column:AlmLevel_ID;default:0"
}
然后执行插入数据,插入成功,难道标记为PrimaryKey以后,主键必须是自增类型?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨