You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error 1075: Incorrect table definition; there can be only one auto column and it must be defined as a key
例子:
type Area struct{
ID uint `gorm:"primarykey"` // 主键ID
Code int `json:"code" form:"code" gorm:"column:code;type:int"`
Schools []School `json:"schools" gorm:"many2many:school_areas;foreignKey:Code;joinForeignKey:area_id;references:ID;JoinReferences:school_system_id"`
}
type School struct{
ID uint `gorm:"primarykey"` // 主键ID
Areas []AreaModel `json:"areas" gorm:"many2many:school_areas;foreignKey:ID;joinForeignKey:school_system_id;references:Code;JoinReferences:area_id"`
}
Description
多对多关联,表迁移的时候,如果中间表对应的关联表不是主键id的话,创建会报错,报错内容为:
例子:
其中中间表为
school_areas
表2个主表
自动迁移的时候就会报错,生成的sql为
数据库运行报1075错误,数据库版本为 5.7+
go版本为 1.16
gorm版本为 v1.21.12
The text was updated successfully, but these errors were encountered: