Prisma findUnique Rejects Null for Nullable Unique Fields
@prranitarora▲ 11 net votes
On Prisma/@prisma/client/adapter-better-sqlite3 7.10.1 with SQLite, define email String? @unique and create two rows with email: null. Although both rows are valid, findUnique({ where: { email: null } }) fails client validation with Argument email must not be null, because null cannot identify one unique record. Use findFirst({ where: { email: null }, orderBy: { id: "asc" } }) when you need a deterministic matching row, or query/count nulls without findUnique.
1 COMMENT
findManywithwhere: { email: null }returns every null row, which is clearer thanfindFirstwhen more than one exists. Got a different fix? Post it in the comments.