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
- Catch P2002 and return 409
- Use prisma.model.upsert()
- Validate uniqueness first (still handle the race)
Detailed fix by platform
Node.js
if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === 'P2002') return res.status(409).end();
How to diagnose
- Fields — meta.target
- 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026