Prisma Error P2014: Required Relation Violation

Prisma error P2014 (Required Relation Violation) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

Error code P2014 Prisma Last verified 2026-08-19

Quick Answer

Read error.meta.relation_name to identify the required relation being violated. If that does not apply, create children with nested create or connect to an existing parent in the same call — the full checklist is below.

Error Code

Error code: P2014
Official name: Required Relation Violation
Service: Prisma

What does this error mean?

The change you are trying to make would violate the required relation '{relation_name}' between the {model_a_name} and {model_b_name} models.

Common Causes

How to Fix

  1. Read error.meta.relation_name to identify the required relation being violated
  2. Create children with nested create or connect to an existing parent in the same call
  3. Never disconnect/set null on a relation marked required in the schema - either make it optional (?) or always provide a target
  4. For deletes, handle children first (deleteMany or cascade) or relax onDelete in the schema

Code Examples

Connect required relation at create time typescript
await prisma.comment.create({
  data: {
    text,
    post: { connect: { id: postId } },
  },
})

The required post relation is satisfied in the same operation, avoiding a second failing update.

Framework-Specific Fixes

prisma-client

Nest the dependent write inside the parent create so the required relation is satisfied atomically.

await prisma.post.create({
  data: {
    title,
    author: { connect: { id: authorId } }, // required relation fulfilled
  },
})
nestjs

Validate that the parent exists (and pass its id) before creating children; answer 400/404 accordingly.

const author = await this.prisma.user.findUnique({ where: { id: authorId } })
if (!author) throw new NotFoundException('Author')
return this.prisma.post.create({
  data: { title, authorId: author.id },
})

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P2014?

Most often this happens when creating a child record whose relation to the parent is required (non-optional) without connecting it, or when disconnecting a required relation (e.g. disconnect: true on a non-optional relation).

How do I fix Prisma error P2014?

Read error.meta.relation_name to identify the required relation being violated.

Which frameworks have documented fixes for error P2014?

This page documents fixes for: prisma-client, nestjs.

Official Sources

This page is based on the official Prisma documentation linked below and adds practical troubleshooting guidance on top.