VectleSkillsEach model must have at least one unique criteria that has only required fields.

Each model must have at least one unique criteria that has only required fields.

Export

Fixes the Prisma schema validation error 'Each model must have at least one unique criteria that has only required fields' (P1012) by giving the model a @id, @unique, or composite @@id/@@unique on required fields. Use when prisma validate or generate fails with this message. Not for database connection errors or migration failures.

TL;DR: Add @id, @unique, or a composite @@id/@@unique to your model, on fields that are required (not optional). Then npx prisma validate passes. Prisma needs at least one unique way to address a single record.

error: Each model must have at least one unique criteria that has only required fields.

Steps

  1. Find the model the error names and give it a unique criterion. Pick the first option that fits:
   model User {
     id    Int    @id @default(autoincrement())
     email String @unique
   }

or for composite keys:

   model Membership {
     userId String
     orgId  String
     @@id([userId, orgId])
   }

Expected: the criterion covers only required fields (no ? on any of them).

  1. Run validation:
   npx prisma validate

Expected: The schema at prisma/schema.prisma is valid.

  1. Regenerate the client and continue your migration:
   npx prisma generate

Expected: Generated Prisma Client with no validation errors.

When to use

  • prisma validate, prisma generate, or prisma migrate dev fails with the exact unique-criteria message
  • You are modeling a join table or a legacy table with no primary key

When not to use

  • The error is about a datasource URL or protocol: that is a different P1012 message
  • You actually want keyless models (MongoDB): use @@ignore or the MongoDB connector rules instead

Compatibility

Prisma schema validation, all versions 2.x through 7.x. PostgreSQL, MySQL, SQL Server, SQLite.

Variant phrasing: Each model must have at least one unique criteria that has only required fields on a model where every field is optional

Making the unique field required is the point: @unique on an optional field still fails validation. Change the field to required or pick a different field.

Why it happens

Prisma Client's findUnique, update, and delete need a guaranteed-unique lookup. A model with no unique criterion cannot support those operations, so the schema is rejected at validation time before any database is touched.

Edge cases

  • Legacy tables truly without a unique column: add a surrogate auto-increment id in the migration.
  • Composite @@unique on two optional fields still fails; every field in the criterion must be required.
  • Views (not tables): map them with @@ignore or query via raw SQL instead of modeling them as writable models.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=Each+model+must+have+at+least+one+unique+criteria+that+has+only+required+fields.&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.