Prisma ORM · Schema

Define a relation

A one-to-many relation uses a foreign key field and a @relation attribute.

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int

  @@index([authorId])
}

Official Prisma ORM documentation

More schema commands

All schema commands · Prisma ORM cheatsheet

Was this page helpful?