The foreign key we added six years late

A column named customer_id with no constraint, and 312 rows pointing at customers that had been deleted.

-- find the orphans first
SELECT o.id, o.customer_id FROM orders o
LEFT JOIN customers c ON c.id = o.customer_id
WHERE o.customer_id IS NOT NULL AND c.id IS NULL;
-- 312 rows, oldest 2017

-- then, and only then
ALTER TABLE orders
  ADD CONSTRAINT fk_orders_customer
  FOREIGN KEY (customer_id) REFERENCES customers(id);

Deciding what to do with the orphans is the work — ours became a synthetic “deleted customer” record, because the orders were real and had financial history. The constraint then prevents the next six years of the same, and the cost is that a delete now fails loudly instead of leaving debris, which is a change in behaviour somebody has to be told about.