Prisma Error P2001: Record Not Found in Where Condition

Prisma error P2001 (Record Not Found in Where Condition) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

Error code P2001 Prisma Last verified 2026-08-19

Quick Answer

Log the failing model_name, argument_name and argument_value from the error message. If that does not apply, verify the record exists with findUnique() before the write, or switch to update/delete semantics that tolerate absence — the full checklist is below.

Error Code

Error code: P2001
Official name: Record Not Found in Where Condition
Service: Prisma

What does this error mean?

The record searched for in the where condition ({model_name}.{argument_name} = {argument_value}) does not exist

Common Causes

How to Fix

  1. Log the failing model_name, argument_name and argument_value from the error message
  2. Verify the record exists with findUnique() before the write, or switch to update/delete semantics that tolerate absence
  3. Check for id type mismatch: string ids vs numeric ids, or wrong tenant scoping
  4. Consider updateMany()/deleteMany() when the operation should be a no-op on missing rows
  5. If using upsert() with a where that references a non-unique field, P2001 can surface - use unique fields only

Code Examples

Guard then update typescript
const existing = await prisma.user.findUnique({ where: { id } })
if (!existing) throw new NotFoundException(`User ${id}`)
return prisma.user.update({ where: { id }, data: { name } })

Explicit guard keeps the 404 behavior visible instead of leaking a Prisma error.

No-op update with updateMany typescript
const { count } = await prisma.user.updateMany({
  where: { id },
  data: { name },
})
// count === 0 when nothing matched

updateMany never throws for missing rows - use the count to decide the response.

Framework-Specific Fixes

express

Catch P2001 in handlers and answer 404, mirroring REST semantics for missing resources.

catch (e) {
  if (e.code === 'P2001') {
    return res.status(404).json({ error: 'Resource not found' })
  }
  throw e
}
prisma-client

Prefer findUnique with a guard so the missing-record case is explicit in business logic.

const user = await prisma.user.findUnique({ where: { id } })
if (!user) {
  return notFound()
}
await prisma.user.update({ where: { id }, data: { lastSeen: new Date() } })

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P2001?

Most often this happens when findUnique() with an id that was never created or was already deleted, or when update() or delete() on a record that disappeared between read and write.

How do I fix Prisma error P2001?

Log the failing model_name, argument_name and argument_value from the error message.

Which frameworks have documented fixes for error P2001?

This page documents fixes for: express, prisma-client.

Official Sources

This page is based on the official Prisma documentation linked below and adds practical troubleshooting guidance on top.