type Player struct {
Id int64 gorm:"column:Id"
Sex bool gorm:"column:Sex"
CreateAt time.Time gorm:"column:CreateAt"
// ......
}
db.Model(&Player{}).Where(" Id=? and Sex=0 ", 1001082).Updates(map[string]interface{}{
"Sex": 1,
"CreateAt": time.Now(),
})
表player的sex字段在mysql里是tinyint类型,如果Sex定义成bool类型,发现执行过程中转换数据类型已经报错了:“failed to set value %+v to filed %s”,但这个错误没有被处理,不影响最终的SQL生成:"update player set CreateAt='2022-03-08 13:55:39.385',sex=1 where id=1001082 and sex=0";
我在gormV1也有这个问题,最终的SQL会变成:"update player set CreateAt='2022-03-08 13:55:39.385',sex=false where id=1001082 and sex=0"。
我们项目用的gormV1,为什么不panic呢,上层scope.callCallbacks可以捕获错误,从而告知应用程序。
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 ✨
Comment From: jinzhu
sorry, but gorm v1 is already not maintained any more
Comment From: YunCaiCaoYuan
gormV2也有这个错误,但不影响最终SQL,请问下为什么不抛出这个错误呢?