i'm making an ecommerce app but i got an error coming from the prisma.schema file, and it happens when i try to delete a product from the admin dashboard app in which there is this file, here it's the code in the file:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model Store {
id String @id @default(uuid())
name String
userId String
billboards Billboard[] @relation("StoreToBillboard")
categories Category[] @relation("StoreToCategory")
products Product[] @relation("StoreToProduct")
sizes Size[] @relation("StoreToSize")
colors Color[] @relation("StoreToColor")
orders Order[] @relation("StoreToOrder")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Billboard {
id String @id @default(uuid())
storeId String
store Store @relation("StoreToBillboard", fields: [storeId], references: [id])
label String
imageUrl String
categories Category[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
}
model Category {
id String @id @default(uuid())
storeId String // Foreign Key to Store
store Store @relation("StoreToCategory", fields: [storeId], references: [id])
billboardId String // Foreign Key to Billboard
billboard Billboard @relation(fields: [billboardId], references: [id])
name String
products Product[] @relation("CategoryToProduct")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
@@index([billboardId])
}
model Product {
id String @id @default(uuid())
storeId String // Foreign Key to Store
store Store @relation("StoreToProduct", fields: [storeId], references: [id])
categoryId String // Foreign Key to Category
category Category @relation("CategoryToProduct", fields: [categoryId], references: [id])
name String
price Decimal
isFeatured Boolean @default(false)
isArchived Boolean @default(false)
sizeId String // Foreign Key to Size
size Size @relation(fields: [sizeId], references: [id])
colorId String // Foreign Key to Color
color Color @relation(fields: [colorId], references: [id])
images Image[] // Relation to Image model
orderItems OrderItem[] @relation("OrderItemToProduct")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
@@index([categoryId])
@@index([sizeId])
@@index([colorId])
}
model Order {
id String @id @default(uuid())
storeId String // Foreign Key to Store
store Store @relation("StoreToOrder", fields: [storeId], references: [id])
orderItems OrderItem[] // Relation to OrderItem model
isPaid Boolean @default(false)
phone String @default("")
address String @default("")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
}
// Intermediary for a many-to-many relationship
model OrderItem {
id String @id @default(uuid())
orderId String // Foreign Key to Order
order Order @relation(fields: [orderId], references: [id])
productId String // Foreign Key to Product
product Product @relation("OrderItemToProduct", fields: [productId], references: [id], onDelete: Cascade)
@@index([orderId])
@@index([productId])
}
model Size {
id String @id @default(uuid())
storeId String // Foreign Key to Store
store Store @relation("StoreToSize", fields: [storeId], references: [id])
name String
value String
products Product[] // Relation to Product model
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
}
model Color {
id String @id @default(uuid())
storeId String // Foreign Key to Store
store Store @relation("StoreToColor", fields: [storeId], references: [id])
name String
value String
products Product[] // Relation to Product model
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([storeId])
}
model Image {
id String @id @default(uuid())
productId String // Foreign Key to Product
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
url String // URL of the image
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([productId])
}
and this is the error: [PRODUCT_DELETE] PrismaClientKnownRequestError: Invalid prisma.product.delete() invocation: The change you are trying to make would violate the required relation 'OrderItemToProduct' between the OrderItem and Product models.
First the schema has not the relation 'OrderItemToProduct', but even after i insert it the error is stille there, hope you could help me.