在这个例子中,101有一个,还有一个有一个.
但当我跑prisma format
时,抛出错误:
error: Error validating field `image` in model `Product`: The relation field `image` on Model `Product` is missing an opposite relation field on the model `ProductImage`. Either run `prisma format` or add it manually.
我的schema.prisma
:
model ProductImage {
id String @id @default(uuid()) @db.VarChar(36)
product_id String
product Product @relation(fields: [product_id], references: [id])
src String @db.VarChar(255)
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@map("product_image")
}
model Product {
id String @id @default(uuid()) @db.VarChar(36)
image_id String
image ProductImage @relation(name: "main_image", fields: [image_id], references: [id])
images ProductImage[]
slug String @unique(map: "slug") @db.VarChar(255)
title String @db.VarChar(255)
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@map("product")
}