# X_DB_FOREIGN_KEY_VIOLATION

## Means

a foreign key constraint rejected the row

## Typical cause

SQLSTATE `23503` — the parent row is absent, was deleted between the read and the write, or belongs to another tenant (a [same-tenant key](/entities-and-migrations#same-tenant-keys) answers absent and foreign alike, and the memory driver refuses only the second). `meta.constraint` names the key

## Fix

insert the row the constraint `cause` names points at first, in the same `withTransaction(...)` — or drop the write, because the parent it names is gone or is not this tenant's

[Entity and database](/error-codes#entity-and-database)
