Prisma P2002 🟩 Node.js

PrismaClientKnownRequestError P2002: Unique constraint failed on the fields: (`email`)

A Prisma create/update violated a unique constraint.

Seen on: Node.js

Meaning

P2002 is Prisma’s code for unique violations; meta.target lists the fields.

Common causes

  • Duplicate value for a @unique field
  • Race between concurrent creates
  • Missing upsert logic

⚡ Quick fix

  1. Catch P2002 and return 409
  2. Use prisma.model.upsert()
  3. Validate uniqueness first (still handle the race)

Detailed fix by platform

Node.js

  1. if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === 'P2002') return res.status(409).end();

How to diagnose

  1. Fields — meta.target
  2. Flow — Concurrent requests?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.