Prisma Error P2025: Required Record Not Found

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

Error code P2025 Prisma Last verified 2026-08-19

Quick Answer

Inspect error.meta.cause and error.meta.model to locate the operation and the missing record. If that does not apply, verify the id was really created by the database (not undefined, NaN, or a fake value) before connecting — the full checklist is below.

Error Code

Error code: P2025
Official name: Required Record Not Found
Service: Prisma

What does this error mean?

An operation failed because it depends on one or more records that were required but not found. {cause}

Common Causes

How to Fix

  1. Inspect error.meta.cause and error.meta.model to locate the operation and the missing record
  2. Verify the id was really created by the database (not undefined, NaN, or a fake value) before connecting
  3. Guard with a findFirst() and return a 404-style response instead of crashing
  4. For deletes, treat an already-missing record as success (idempotent delete) when the business allows it
  5. Check the schema: make the relation optional (?) or use connectOrCreate when a missing target is legitimate

Code Examples

Read the missing-record cause typescript
try {
  await prisma.profile.delete({ where: { userId } })
} catch (e) {
  if (e.code === 'P2025') {
    // meta.cause explains which required record was missing
    console.log(e.meta.cause)
  }
}

P2025 wraps a short description of the missing dependency in meta.cause.

Idempotent delete without crashing typescript
await prisma.user.deleteMany({ where: { id } })
// deleteMany never throws when the row is absent

deleteMany() is naturally idempotent - no record means no-op instead of P2025.

Framework-Specific Fixes

nestjs

Map P2025 to HTTP 404 Not Found in the global filter and include the model name for debuggable API errors.

if (e.code === 'P2025') {
  return response.status(404).json({
    message: `${e.meta.model ?? 'Record'} not found`,
  })
}
express

Catch P2025 in route handlers and answer 404 instead of 500 so clients can react to missing resources.

router.delete('/users/:id', async (req, res) => {
  try {
    await prisma.user.delete({ where: { id: req.params.id } })
    res.status(204).end()
  } catch (e) {
    if (e.code === 'P2025') return res.status(404).json({ error: 'User not found' })
    throw e
  }
})
prisma-client

Use findFirst() before nested writes so the absence of the parent record is handled explicitly.

const parent = await prisma.post.findFirst({ where: { id: postId } })
if (!parent) {
  return { status: 404, body: 'Post not found' }
}
await prisma.comment.create({
  data: { text, postId: parent.id },
})

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P2025?

Most often this happens when deleting or updating a record by an id that no longer exists, or when nested write referencing a related record with connect: { id } when that id is missing.

How do I fix Prisma error P2025?

Inspect error.meta.cause and error.meta.model to locate the operation and the missing record.

Which frameworks have documented fixes for error P2025?

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

Official Sources

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