/// these are the models
model Menu {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
menuName String
isPdfPublic Boolean
// menuCategories MenuCategory[]
menuPdf MenuPdf[]
menuCategories MenuCategory[]
entity Entity @relation(fields: [entityId], references: [id])
entityId String @unique
}
model MenuCategory {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
categoryName String
categoryPublic Boolean
// categoryTag String // the category tag is like drinks/food/inventory/perishables...
// menu id
menuId Int @unique
Menu Menu @relation(fields: [menuId], references: [id])
menuItem MenuItem[]
}
///this is the addModelFunction'
export async function addCategory({
menuId,
categoryName,
categoryPublic=false,
}:AddCategory) {
try {
const category = await prisma?.menuCategory.create({
data: {
menuId,
categoryName,
categoryPublic: false,
}
});
console.log("category from add category", category);
return category;
} catch (error) {
throw new Error(the error is from addCategory ${error})
// console.log('error', error);
}
}
////this is the error
Invalid prisma.menuCategory.create() invocation:
Unique constraint failed on the constraint: MenuCategory_menuId_key
at addCategory (./src/lib/entity/entityCategories.ts:30:15)
32 | return category;
33 | } catch (error) {
34 | throw new Error(
the error is from addCategory ${error})
| ^