Search code examples
postgresqlnext.jsprismasupabase

Prisma schema doesn't match DB schema


I've got a Person table that looks like this in the schema:

model Person {
  id              String    @id @default(uuid())
  firstName       String?
  lastName        String?
  roles           Role[]
  middleNames     String?
  gender          String?
  dob             DateTime?
  email           String?
  phone           String?
  address         String?
  notes           String?
  nationality     String?
  people          Person[]  @relation("RelatedPeople")
  private         String[]
  cases           Case[]
  lastEdited      DateTime?
  personTasks     String[]
  Person          Person?   @relation("RelatedPeople", fields: [personId], references: [id])
  personId        String?
  additonalFields Json?     @relation(fields: [teamId], references: [id])
  Team            Team?
  teamId          String?
}

And a Role table that looks like this:

model Role {
  id       String  @id @default(uuid())
  name     String
  icon     String?
  Team     Team?   @relation(fields: [teamId], references: [id])
  teamId   String?
  Person   Person? @relation(fields: [personId], references: [id])
  personId String?
}

But I can't see the roles column on Person in my database (Supabase psql). Neither can I see the relationship/join table that should have been created between Person and Role. So when I try to create a person with a role like so:

      const person = await prisma.person.create({
        data: { ...req.body, roles: { createMany: { data: roles } } },
      });

I get the following error:

  Unknown arg `personId` in data.roles.createMany.data.0.personId for type RoleCreateManyPersonInput. Did you mean `teamId`? Available args:
  type RoleCreateManyPersonInput {
    id?: String
    name: String
    icon?: String | Null
    teamId?: String | Null
  }

I've tried doing prisma generate to update the client, and I've done prisma migrate and prisma db push several times, but it always says "nothing to update."

Very confused, please help! 🙏


Solution

  • Because you're using nested write, so you don't need to provide personId. Just remove personId in your roles data, that will work.