Hello I am having the same problem with a trigger, I do not understand my error. The script compiles but when I delete an element I have this error
CREATE OR REPLACE FUNCTION delete_foreign_key() RETURNS TRIGGER AS $_$
BEGIN
delete from planning.ordrelivraison_history
where ordrelivraison_history.ordrelivraisonid = old.planning.ordrelivraison.ordreid;
RETURN OLD;
END;
$_$ LANGUAGE plpgsql;
Create trigger delete_foreign_key_in_order_delivery_history
after delete
on planning.ordrelivraison_history
for each row
execute procedure delete_foreign_key();
------------------------------------------------------
delete
from planning.ordrelivraison
where ordreid = 1656
Voici l'erreur
ERROR: ERROR: UPDATE or DELETE on the "delivery order" table violates the foreign key constraint "Ordrelivraison_history_ordreid" from the "ordrelivraison_history" table DETAIL: The key (orderid) = (1656) is always referenced from the “ordrelivraison_history” table.
SQL state: 23503
$_$for the function body.