Does Prisma support composite keys with one of the attribute being NULL for PostgreSQL?

Viewed 103

In PostgreSQL you can make a table with 2 columns as the composite key of that table, with one of them being NULL-able. I was just wondering how I can achieve this with Prisma.

In the current version of Prisma that I have (3.14.0), Prisma does allow composite key using @@id([column1,column2]), but only if those two columns are mandatory.

1 Answers

No, Prisma doesn't support composite keys with optional columns. ID Definitions are required.

Example:

This would work

model Post {
  title   String
  content String

  @@id([title, content])
}

But this wouldn't as column content is defined as optional

model Post {
  title   String
  content String?

  @@id([title, content])
}

You can create a Feature Request here to support allowing nullable columns in composite id.

Related