GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
版本
V1
Model定义如下:
type Demo struct {
ID int64 `gorm:"column:id;AUTO_INCREMENT"`
TenantID string `gorm:"column:tenant_id;size:16;not null;default:'';index:idx_tenant;unique_index:uniq_tenant_name;unique_index:uniq_tenant_fingerprint"`
Name string `gorm:"column:name;size:16;not null;default:'';unique_index:uniq_tenant_name"`
Fingerprint string `gorm:"column:fingerprint;size:32;not null;default:'';unique_index:uniq_tenant_fingerprint'"`
CreatedAt int64 `gorm:"column:created_at;type:int unsigned;not null;default:0"`
UpdatedAt int64 `gorm:"column:updated_at;type:int unsigned;not null;default:0"`
DeletedAt int64 `gorm:"column:deleted_at;type:int unsigned;not null;default:0"`
}
AutoMigrate 生成的表SQL如下:
CREATE TABLE `ecs_ssh_key_pair` (
`id` bigint NOT NULL AUTO_INCREMENT,
`tenant_id` varchar(16) NOT NULL DEFAULT '',
`name` varchar(16) NOT NULL DEFAULT '',
`fingerprint` varchar(32) NOT NULL DEFAULT '',
`created_at` int unsigned NOT NULL DEFAULT '0',
`updated_at` int unsigned NOT NULL DEFAULT '0',
`deleted_at` int unsigned NOT NULL DEFAULT '0'',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_tenant_fingerprint` (`tenant_id`,`fingerprint`),
UNIQUE KEY `uniq_tenant_name` (`name`),
KEY `idx_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
其中:索引 uniq_tenant_fingerprint 没问题,但是索引 uniq_tenant_name 少了字段 tenant_id
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 2 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: shenghui0779
这个bug很严重啊
Comment From: frederikhors
Is this fixed, @shenghui0779?
Comment From: ChinaRedArmy1930
这个bug解决了吗? 貌似没有吧 我这边使用的是 v1.24.0版本
type Location struct {
Id int `gorm:"primaryKey,autoIncrement,comment:地理位置表的自增id,<-:create" json:"id,omitempty"`
ClassId string `gorm:"index:location_classId_type_index,size:50,comment:类型对应的数据id\,可能是项目id或者活动id,not null" json:"ClassId,omitempty"`
Province string `gorm:"size:50,comment:地理位置省" json:"province,omitempty"` //省
City string `gorm:"size:50,comment:地理位置市" json:"city,omitempty"` //市
County string `gorm:"size:50,comment:地理位置县" json:"county,omitempty"` //县
ClassType int `gorm:"index:location_classId_type_index,comment:id类型\,0代表项目. 1代表活动" json:"classType,omitempty"`
}
生成的表结构没有联合索引