我在为关系创建外键约束时遇到问题。Belongs to
包含外键的结构:
type Summary struct {
Id string `gorm:"primaryKey"`
OwnerId *string `gorm:"foreignKey:OwnerId references:Id;not null"`
Title string
}
摘要所属的结构:
type Owner struct {
Id string `gorm:"primaryKey"`
Name string
}
它可以毫无问题地在 SQL 中创建表,但 SQL 架构在列上的摘要表中不包含外键约束,因此当所有者不存在时,可以插入摘要。owner_id
POPMUISE
幕布斯6054654
相关分类