Error code

MySQL 1216

MYSQL1216
Database Error Code· An error code returned by a database server such as PostgreSQL or MySQL.

What it means

Cannot add a child row — foreign key constraint fails on INSERT.

How to fix it

  1. Insert the parent row first before inserting the child row.
  2. Wrap both inserts in a transaction to ensure atomicity.
  3. Verify that the referenced parent table and column contain the expected value.

Not affiliated with MySQL. Answer summarized from the manufacturer's manual linked above; consult that source for the authoritative procedure.