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.
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.