Seaquel
PostgreSQL error code

PostgreSQL error 23503

23503 is the SQLSTATE PostgreSQL reports for foreign key violation, in class 23, Integrity Constraint Violation.

SQLSTATE23503
Condition nameforeign_key_violation
Class23 — Integrity Constraint Violation

Reproduce it, then fix it

There is no customer 999 for the order to point to. Deleting a customer who still has orders raises the same error from the other direction. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

INSERT INTO orders (id, customer_id, status)
VALUES (100, 999, 'pending');
INSERT INTO orders (id, customer_id, status)
VALUES (100, 1, 'pending')
RETURNING *;

Source: PostgreSQL documentation, Appendix A