0

Zarar's blog · 22d · discuss

After decades of working with databases I didn't know that NOT VALID was a thing: ALTER TABLE line_item ADD CONSTRAINT line_item_variant_price_id_fkey FOREIGN KEY (variant_price_id) REFERENCES variant_prices(id) NOT VALID This is for cases when you want to add a foreign key to an existing column except that column contains data that would violate a foreign key constraint (e.g., an invalid deleted ID).