type Goods struct { BaseModel CategoryID int32 `gorm:"type:int;not null"` Category Category BrandsID int32 `gorm:"type:int;not null"` Brands Brands }
Goods 是从表,从表中add foreign key关系, reference 主表
alter table 从表名 add [constraint] [外键名称] foreign key(从表中的外键字段名) references 主表(主表的主键); [外键名称]:用于删除外键约束,一般建议以“_fk”结尾。
先删除从表(goods),再删除主表(brands)