Mysql foreign key constraint not working

Hi guys, I'm just making a reference to the foreign keys of the parent table in the child table. When I try to delete a row from the parent table whose link is in the child table, surprisingly this allows me to delete it. I tried to create the child table explicitly, writing on the restriction on deletion, as well as without it, but without help. Any idea why this is happening? .Below is the code I use when creating tables.

CREATE TABLE region ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL ); CREATE TABLE aggregator ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL ); CREATE TABLE gateway ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL, region_id int , aggregator_id int , is_public boolean DEFAULT 0 NOT NULL, FOREIGN KEY (region_id) REFERENCES region(id), FOREIGN KEY (aggregator_id) REFERENCES aggregator(id) ); 
+4
source share
2 answers

Both the parent and child tables must be INNODB tables.

Try:

 CREATE TABLE region ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL ) ENGINE=INNODB; CREATE TABLE aggregator ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL ) ENGINE=INNODB; CREATE TABLE gateway ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(50) NOT NULL, region_id int , aggregator_id int , is_public boolean DEFAULT 0 NOT NULL, FOREIGN KEY (region_id) REFERENCES region(id), FOREIGN KEY (aggregator_id) REFERENCES aggregator(id) ) ENGINE=INNODB; 
+7
source

You want to say that if you delete the parent table and the child table, it is automatically deleted? If so, follow the cascading rules.

0
source

All Articles