Prisma P2002: Unique constraint failed on the {constraint}

Prisma says P2002 Unique constraint failed on the {constraint}? That write hit a unique constraint. The message names the constraint.

Reviewed October 22, 2026

What it means in plain English

Prisma's error reference defines P2002 as: Unique constraint failed on the {constraint}.

Prisma Client throws PrismaClientKnownRequestError when the query engine returns a known error related to the request. The reference gives a unique constraint violation as the example. That error has code, meta, message, and clientVersion. meta is additional information about the error. The reference's example of the field that caused the error is { target: [ 'email' ] }.

P2003 is a different code: Foreign key constraint failed on the field {field_name}. P2025 means an operation failed because it depends on one or more records that were required but not found. P2021 means the table {table} does not exist in the current database.

Likely causes

  • The write uses a value that fails the unique constraint named in the P2002 message.
  • meta.target names the field. The reference's example is email.
  • The failure is a foreign key, a missing required record, or a missing table. Those are P2003, P2025, and P2021 on the same page.

How to fix it, step by step

  1. Read code. Stay on this page when it is P2002.
  2. Read {constraint} in the message, and read meta for the extra detail. The reference's example of that detail is { target: [ 'email' ] }.
  3. P2002 is the failure of the unique constraint named in the message. The reference does not add another procedure. meta is where it puts extra detail, and its example of the field that caused a known request error is { target: [ 'email' ] }.
  4. If the code is P2003, the failure is the foreign key on {field_name}, not a unique constraint.
  5. If the code is P2021, the table in the message is not in the current database. If the code is P2025, a required record was not found.

How to check it worked

  • The same write no longer throws P2002.
  • code on the next error, if there is one, is not P2002.

Sources

More Database connections fixes

Keep going on your own.

The guides stay free. A deep leak report is $15. Fix packs are $24, or $49 for all three. There is no done-for-you repair.

See products