我正在尝试使用下面的文件生成种子数据。当它运行时,它告诉我journalEntry项需要一个用户,但我不知道为什么,docs中的示例在upsert
运行时没有指定用户。
async function main() {
const food = await prisma.food.upsert({
where: {
id: 1,
},
create: {
name: 'Protein shake',
meal: 'DINNER',
journalEntry: {
create: {
user: { // this is the problem
create: {id: 1}
}
}
},
macros: {
create: {
calories: 120,
protein: 24,
carbs: 3,
fat: 0,
}
},
journalEntryId: 1,
nutrientProfileId: 1,
},
})
console.log(food);
}
模型
model User {
id Int @id @default(autoincrement())
username String @unique
targetMacros NutrientProfile @relation(fields: [nutrientProfileId], references: [id])
journalEntries JournalEntry[]
nutrientProfileId Int
}
model NutrientProfile {
id Int @id @default(autoincrement())
calories Int @default(0)
protein Int @default(0)
carbs Int @default(0)
fat Int @default(0)
User User[]
Food Food[]
}
model JournalEntry {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
journalItems Food[]
notes String? @db.VarChar(255)
user User @relation(fields: [userId], references: [id])
userId Int
}
model Food {
id Int @id @default(autoincrement())
name String
macros NutrientProfile @relation(fields: [nutrientProfileId], references: [id])
createdAt DateTime @default(now())
journalEntry JournalEntry? @relation(fields: [journalEntryId], references: [id])
journalEntryId Int?
nutrientProfileId Int
meal Meal
}
enum Meal {
BREAKFAST
LUNCH
DINNER
SNACK
}
1条答案
按热度按时间j2qf4p5b1#
也许作者认为读者已经读完了阅读以前的相关文章。
primsa中的关系
对于您的情况,您可以如上所述更新prisma模型以删除模型之间的强关系来修复错误,或者首先编写代码以种子用户。