【发布时间】:2021-10-27 07:08:26
【问题描述】:
我的目标是归档与 gorm 的“有很多”关系
我不想生成任何 ID,所以我故意不在我的结构中使用 gorm.Model
我设置了两个结构,例如:
type Application struct {
Name string `json:"name" gorm:"primaryKey"`
Description string `json:"description"`
Translations []Translation `json:"titles" gorm:"foreignKey:ApplicationName;references:Name"`
}
type Translation struct {
ApplicationName string `json:"applicationName" gorm:"primaryKey"`
Locale string `json:"locale" gorm:"primaryKey"`
Value string `json:"value"`
}
Translation.ApplicationName 应该是 Applications 的外键
(Translation.ApplicationName + Translation.Locale) 翻译的主键
创建应用程序后
{
"name" : "postedApplication1",
"description" : "postedDescription3",
"titles" : [
{
"locale": "de-DE",
"value":"deutsch"
},
{
"locale": "de-AT",
"value":"AT"
}
]
}
我收到以下错误
ON CONFLICT 子句不匹配任何 PRIMARY KEY 或 UNIQUE 约束 [0.065ms] [rows:0] 插入
translations(application_name,locale,value) 价值观 ("postedApplication1","de-DE","deutsch"),("postedApplication1","de-AT","AT") ON CONFLICT (application_name,locale) 做更新集application_name=excluded.application_name
和
ON CONFLICT 子句不匹配任何 PRIMARY KEY 或 UNIQUE 约束 [0.531ms] [rows:0] 更新
applicationsSETdescription="postedDescription3" 在哪里name= "postedApplication1" [杜松子酒] 2021/08/27 - 11:23:00 | 200 | 841.953µs | 127.0.0.1 | 发布“/应用程序”
有人知道我做错了什么
【问题讨论】: