mysql - How can I set COLLATION of a field to utf8_general_ci with GORM? -
i have string-type field in mysql database case-insenstive , unique. used following model:
type user struct { id int64 `json:"id" sql:"auto_increment"` email string `json:"email" sql:"unique_index"` }
which makes email
unique,
type user struct { id int64 `json:"id" sql:"auto_increment"` email string `json:"email" sql:"unique_index;collation(utf8_general_ci)"` }
seems have no effect.
how can set collation of field utf8_general_ci gorm?
you can use sql tag in field want change, this:
type user struct { gorm.model name `sql:"type:varchar(5) character set utf8 collate utf8_general_ci"` }
Comments
Post a Comment