Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过gormt生成的model autoIncrement tag会被type tag覆盖。 #218

Closed
NadiaSama opened this issue Aug 26, 2022 · 5 comments
Closed

Comments

@NadiaSama
Copy link

type TestRecord struct {
	ID                  uint64  `gorm:"autoIncrement:true;primaryKey;column:id;type:bigint(20) unsigned;not null" json:"id"`
}

以MYSQL为例在生成sql时 autoIncrement:true 会给ID column datatype·追加AUTO_INCREMENT`。

type:bigint(20) unsigned;not null会给ID column datatype设置bigint(20) unsigned NOT NULL,而且由于type 指定了specified database data type按照目前gorm的规则应给是specificed database data type会覆盖掉其他datatype设置,这导致之前的AUTO_INCREMENT被覆盖。

@NadiaSama
Copy link
Author

如果column设置了specificed database data type且设置了自增,可以把AUTO_INCREMENT追加到type tag

@NadiaSama
Copy link
Author

NadiaSama commented Aug 26, 2022

not null tag不会被覆盖。。。

@NadiaSama
Copy link
Author

NadiaSama commented Aug 26, 2022

我先在gorm提个Issue看能不能给修复

@xxjwxc
Copy link
Owner

xxjwxc commented Aug 26, 2022

好的,这里也可以提pr,我来覆盖

@NadiaSama
Copy link
Author

我先在gorm提个Issue看能不能给修复

问题找到了是通过gorm链接mysql使用的dialector有问题导致,这个问题已经被处理 go-gorm/mysql#83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants