Your Question

使用定长字符串作为主键

ID    string `gorm:"primarykey;char(44)"`

上面这样写报Error 1170错误:

Error 1170: BLOB/TEXT column 'id' used in key specification without a key length

搜了下Issue,发现需要加size标签:

ID    string `gorm:"primarykey;char(44);size:44"`

此时AutoMigrate却将char视为了varchar:

[0.315ms] [rows:0] CREATE TABLE `test` (`id` varchar(44))...

以及,为什么明明指定了char标签,却使用longtext建表?


见鬼,string都解析成longtext了。。。

type Test struct {
    Name string
}

db.Debug().AutoMigrate(&Test{})
[5.377ms] [rows:0] CREATE TABLE `tests` (`name` longtext)

The document you expected this should be explained

字段标签

Expected answer

这是为何?longtext是怎么出来的?

Comment From: congjunhua

忘了+type..