Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On delete restrict mysql is not working

I want to prevent deleting from parent table when he has children in other tables that.

I make like this

ALTER TABLE constant_det_tb 
ADD CONSTRAINT fk_idparent
FOREIGN KEY (idparent)
REFERENCES constant_tb(id) ON DELETE RESTRICT

When I delete from parent constant_tb table, it delete the rows even the table has reference to another tables and it has records reference to it.

like image 468
palAlaa Avatar asked Oct 19 '25 12:10

palAlaa


1 Answers

Make sure you have InnoDB as storage engine for all affected tables.

Check this (if not already) : http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

ON DELETE RESTRICT 

reference option is all you need to achieve this.

like image 185
rkosegi Avatar answered Oct 21 '25 01:10

rkosegi