Skip to content

Potential mistakes

esafar edited this page Apr 27, 2023 · 1 revision

Here are the potential mistakes that you could encounter:

Potential mistakes!

Error validating field `post` in model `CategoriesOnPosts`: The relation field `post` on model `CategoriesOnPosts` is missing an opposite relation field on the model `Post`. Either run `prisma format` or add it manually.

This is coming from the prisma schema which is not well formated. Don't forget to add this line:

model Post {
  id         Int                 @id @default(autoincrement())
  title      String
  // categories CategoriesOnPosts[] // <-- add this line to fix the issue
}

model Category {
  id    Int                 @id @default(autoincrement())
  name  String
  posts CategoriesOnPosts[]
}

model CategoriesOnPosts {
  post       Post     @relation(fields: [postId], references: [id]) // <-- the error comes from here 
  postId     Int // relation scalar field (used in the `@relation` attribute above)
  category   Category @relation(fields: [categoryId], references: [id])
  categoryId Int // relation scalar field (used in the `@relation` attribute above)
  assignedAt DateTime @default(now())
  assignedBy String

  @@id([postId, categoryId])
}