使用的gorm版本为v1.24.6
模型定义如下:
type User struct {
BaseModel
Account string `json:"account" gorm:"type:varchar(64);unique;not null;"`
Name string `json:"name" gorm:"type:varchar(128);"`
Password string `json:"-"`
Email string `json:"email" gorm:"type:varchar(128);unique;not null;"`
Avatar string `json:"avatar" gorm:"type:text;not null;"`
WecomID string `json:"wecom_id" gorm:"type:varchar(128);"`
IsEmployee bool `json:"is_employee" gorm:"type:tinyint(1);default:1;"`
IsAdmin bool `json:"is_admin" gorm:"type:tinyint(1);default:0;"`
IsHR bool `json:"is_hr" gorm:"type:tinyint(1);default:0;"`
Title string `json:"title" gorm:"type:varchar(128);"`
BasedIn string `json:"based_in" gorm:"type:varchar(64);"`
Language string `json:"language" gorm:"type:varchar(64);default:zh-CN;comment:语言"`
Timezone string `json:"timezone" gorm:"type:varchar(64);default:Asia/Shanghai;comment:时区"`
}
但是我插入数据的时候,结构体IsEmployee中传入的false,但是生成SQL的时候就变成了true,如下图:
当我把模型中的default:1删除后,数据的插入就正常了
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: a631807682
https://gorm.io/docs/create.html#Default-Values