Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL trigger is not called by constraints

I have two (InnoDB) tables with triggers for UPDATE, INSERT and DELETE. They work fine if I work directly on the tables. Further I have a foreign key constraint when I delete a row in tableA all rows in tableB referenced by tableA.id get also deleted. That also works but the problem is:

A DELETE on tableA triggers the DELETE-trigger for tableA. Then the constraint deletes rows at tableB but no DELETE-triggers for tableB get called. Why? Do constraints do not trigger triggers?

Thanks.

(Triggers are AFTER DELETE. Tried also with BEFORE DELETE without success.)

like image 831
Lorenz Avatar asked Feb 18 '23 07:02

Lorenz


1 Answers

Triggers aren't fired if the delete is caused by a foreign key.

From the manual

Triggers currently are not activated by foreign key actions.

like image 93
a_horse_with_no_name Avatar answered Feb 19 '23 20:02

a_horse_with_no_name