What you need here is connectOrCreate.

So something like this should work:

      await prisma.post.create({
        data: {
          title: 'Hello',
          categories: {
            create: [
              {
                category: {
                  create: {
                    name: 'category-1',
                  },
                },
              },
              { category: { connect: { id: 10 } } },
            ],
          },
        },
      });

You can also read more about this in the docs here

Answer from Ryan on Stack Overflow
🌐
Prisma
prisma.io › home › relations › relations › relations › relations
Relations | Prisma Documentation
Relations in the Prisma schema represent relationships that exist between tables in the database.
🌐
Medium
medium.com › yavar › prisma-relations-2ea20c42f616
Prisma relations
August 19, 2022 - Prisma relations Hi friends, In this post, you’ll learn about Prisma relation Relations A relation is a connection between two models in the Prisma schema. Types of relations There are three …
Discussions

Relations handling with explicit many to many relation
Hi, I’m using PlanetScale to ... with Prisma to build a simple API. I read the documentation about the things to consider, most notably the missing support of foreign keys. I followed the guide to create indexes on foreign keys and also the guide to create explicit many-to-many relations but then I ... More on github.com
🌐 github.com
1
2
November 6, 2023
Multiple relations to the same table
Hey guys! I need to build a table that has two references to the same table. The target table is User, the source table is Absence. The idea is that the Absence table has a reference to the user th... More on github.com
🌐 github.com
3
7
How to create multiple relationships to the same filed in prisma - Stack Overflow
You need to name the relations since you have two relations between same types (Driver <-> Shift and Driver <-> Zone both are connected by two relations each). In cases like this Prisma asks you to name the relations which is what the error message you posted is about. More on stackoverflow.com
🌐 stackoverflow.com
database - Creating relationships in Prisma - Stack Overflow
I am creating a database with the help of Prisma and I have encountered a problem. I have 2 models: User and Lesson. In Lesson I store the IDs of the users who participated in it and the ID of the trainer, which is also a User model. I would like, when downloading Lesson, to be able to immediately get the users who took part in it and the trainer, but not their IDs, but the data of the whole user. I know I need a relationship... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › lemartin07 › understanding-one-to-one-relations-with-prisma-orm-3i3m
Understanding One-to-One Relations with Prisma ORM - DEV Community
June 15, 2024 - Prisma ORM is a powerful tool for managing databases in Node.js and TypeScript projects. One of its most important features is the ability to define relationships between tables, including One-to-One (one-to-one) relationships.
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
Relation queries include: Nested reads (sometimes referred to as eager loading) via select and include ... Prisma Client also has a fluent API for traversing relations.
Find elsewhere
🌐
Medium
medium.com › @imvinojanv › mastering-data-relationships-a-comprehensive-guide-to-building-prisma-schemas-99e1fe50a91d
Mastering Data Relationships: A Comprehensive Guide to Building Prisma Schemas | by Vinojan Veerapathirathasan | Medium
May 21, 2024 - Prisma is an open-source Object-Relational Mapping (ORM) tool that makes complex data interactions easy to handle. Prisma’s ORM approach streamlines database workflows by offering a clear and simple way to interact with the database through ...
Top answer
1 of 3
8

You need to name the relations since you have two relations between same types (Driver <-> Shift and Driver <-> Zone both are connected by two relations each).

In cases like this Prisma asks you to name the relations which is what the error message you posted is about. I think this data model should work:

type Driver {
  id: ID! @unique
  zones: [Zone!] @relation(name: "DriverZones")
  shifts: [Shift!] @relation(name: "DriverShifts")
  preferredZone: Zone @relation(name: "PreferredZone")
  preferredShift: Shift @relation(name: "PreferredShift")
}


type Shift {
  id: ID! @unique 
  drivers: [Driver! ] @relation(name: "DriverShifts") 
}


type Zone {
  id: ID! @unique 
  drivers: [Driver! ] @relation(name: "DriverZones") 
}
2 of 3
0

I would like you to try this way:

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  accountId     String    @unique

  account Account @relation(fields: [accountId], references: [id])

  sessions       Session[]
  TeamHasMembers TeamHasMembers[]
  TeamHasLeaders TeamHasLeaders[]
}

model Team {
  id   String @id @default(cuid())
  name String
  slug String @unique

  TeamHasMembers TeamHasMembers[]
  TeamHasLeaders TeamHasLeaders[]
}

model TeamHasMembers {
  id     String @id @default(cuid())
  userId String
  teamId String
  role   String

  user User @relation(fields: [userId], references: [id])
  team Team @relation(fields: [teamId], references: [id])
}

model TeamHasLeaders {
  id     String @id @default(cuid())
  userId String
  teamId String

  user User @relation(fields: [userId], references: [id])
  team Team @relation(fields: [teamId], references: [id])
}
🌐
Prisma
prisma.io › home › models › models › models › models
Models | Prisma Documentation
Documentation regarding proper location of Prisma Schema including default naming and multiple files. ... A relation is a connection between two models in the Prisma schema.
🌐
VOSviewer
vosviewer.com
VOSviewer - Visualizing scientific landscapes
VOSviewer is a software tool for constructing and visualizing bibliometric networks.
🌐
Prisma
prisma.io › home › schema api › schema api › schema api
Prisma Schema API | Prisma Documentation
See: The @relation attribute. Maps a field name or enum value from the Prisma schema to a column or document field with a different name in the database.
🌐
Lippincott Williams & Wilkins
journals.lww.com › indianjpsychiatry › fulltext › 2026 › 04000 › global_and_regional_level_association_between.1.aspx
Global and regional level association between depression... : Indian Journal of Psychiatry
Furthermore, synthesizing data on the depression and its relationship with glycemic control at both global and regional levels is critical to generate evidence that informs targeted and effective interventions. We aimed to investigate the global and regional level association between depression and glycemic control in T2DM. The current “Systematic Review and Meta-analysis (SRMA)” adhered to the “Preferred Reporting Items for Systematic Reviews and Meta-Analyses 2020 (PRISMA)” guidelines.
🌐
GitHub
github.com › prisma › prisma › discussions › 17823
Using "where" in many-to-many relation · prisma/prisma · Discussion #17823
December 9, 2023 - Trying to figure out how could I get Categories with Expenses created at specific date, any suggestions? Below my prisma schema : It should look something like this, but "where" is not wo...
Author   prisma
🌐
Prisma
prisma.io › blog › prisma-orm-now-lets-you-choose-the-best-join-strategy-preview
Choosing the Best Join Strategy in Prisma ORM: join vs query
February 21, 2024 - Prisma ORM loads relations with database-level joins (a single SQL query with JSON aggregation) or application-level joins (one query per table). Learn how both work and when to use which.
🌐
npm
npmjs.com › package › prisma-generator-typescript-interfaces
prisma-generator-typescript-interfaces - npm
September 4, 2025 - Generate zero-dependency TypeScript interfaces from Prisma schema. Latest version: 3.1.0, last published: 9 months ago. Start using prisma-generator-typescript-interfaces in your project by running `npm i prisma-generator-typescript-interfaces`. There are 0 other projects in the npm registry using prisma-generator-typescript-interfaces.
      » npm install prisma-generator-typescript-interfaces
    
Published   Sep 04, 2025
Version   3.1.0
🌐
Tericcabrel
blog.tericcabrel.com › many-to-many-relationship-prisma
Handle a Many-to-Many relationship with Prisma and Node.js
February 26, 2024 - The model MovieRating represents the intermediary table; inside, we define relationships with Movie and User model. To set two columns as the primary key of a table in Prisma, use @@id().
🌐
TYPE-MOON Wiki
typemoon.fandom.com › wiki › Fate_series
Fate series | TYPE-MOON Wiki | Fandom
June 26, 2026 - Relationships between the various Fate spinoffs from TYPE-MOON Ace Volume 15. ↑ Fate/kaleid liner Prisma Illya Finale TV Anime Revealed for 2027. Anime News Network (2026-07-20).
Top answer
1 of 1
2

you need to add relations to solve this issue as following one to many for coach relation and many to many for lesson users relation

// schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgres"
  url      = env("DATABASE_URL")
}

enum LessonState {
    ACTIVE
    CLOSED
}

model Lesson {
    id          String      @id @default(uuid()) @map("_id") @db.Uuid
    date        DateTime    @default(now())
    subject     String
    description String
    state       LessonState @default(ACTIVE)
    users       User[]   @relation(name: "lesson_users")
    coachId     String   @db.Uuid
    coach User  @relation(name: "coach", fields: [coachId], references: [id])
}

enum UserRoles {
    ADMIN
    USER
}

model User {
    id        String    @id @default(uuid()) @map("_id") @db.Uuid
    name      String
    surname   String
    password  String
    login     String    @unique
    birthDate DateTime
    role      UserRoles @default(USER)
    createdAt DateTime  @default(now())
    myLessons   Lesson[] @relation(name: "lesson_users")
    lessonsITeach    Lesson[] @relation(name: "coach")
}

The following query returns all lessons with a list of the users who participated in it and the the trainer

await prisma.lesson.findMany({
  include: {
    users: true,
    coach: true,
  },
});

to get ids of users that Lesson participated in lesson

await prisma.lesson.findFirst({
      include: {
        users: { select: { id: true } },
        coach: true,
      },
    });

to get all lessons the user participated in and what lessons the user teach

await prisma.user.findFirst({
  include: {
    myLessons: true,
    lessonsITeach: true,
  },
});

to get only ids

await prisma.user.findFirst({
  include: {
    myLessons: { select: { id: true } },
    lessonsITeach: { select: { id: true } },
  },
});