go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.74k stars 3.93k forks source link

the gorm can not hanle boolean field #2148

Closed lvxin1986 closed 5 years ago

lvxin1986 commented 5 years ago

type K8sCluster struct { gorm.Model ApiAddr string gorm:"type:varchar(20);not null;index:clusterApiAddr_idx" LoginUser string gorm:"type:varchar(16);not null" LoginPasswd string gorm:"type:varchar(32);not null" Tag string gorm:"type:varchar(16);unique" TailDomain string gorm:"type:varchar(64);" InSecure bool gorm:"type:boolean;" } if !db.HasTable(&K8sCluster{}) { if err := db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8").CreateTable(&K8sCluster{}).Error; err != nil { panic(err) } } the field InSecure is boolean but gorm convert this file to tinyint I think is a bug

spaghettifunk commented 5 years ago

I believe it's not a bug but the expected behaviour. For example, MySQL does not use the boolean type but the tinyint one to identify the booleans variables (only 0 and 1 values). Boolean is a synonym of tinyint. Postgres has boolean type. From your comment, I believe you are using MySQL (from InnoDB at least), so that's not a bug.