Database Diagnostic

How to Fix Prisma Error P2002: Unique constraint failed on the constraint

Prisma Client threw error code P2002 because a create or update query attempted to insert a record with a value that already exists in a column marked @unique or @@id.

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

Quick Fix Checklist

  1. Use prisma.model.upsert() instead of prisma.model.create() if updating an existing record is acceptable
  2. Catch error instance of Prisma.PrismaClientKnownRequestError and check err.code === "P2002"
  3. Return a descriptive 409 Conflict HTTP response instead of an unhandled 500 server crash
  4. Add client-side debouncing on submit buttons to prevent double-click race conditions