Hello People,

I was just designing my database and I was planning to finally use the new
feature provided by InnoDB : ON DELETE CASCADE


So I tried the example :

CREATE TABLE parent(id INT NOT NULL,
                      PRIMARY KEY (id)) TYPE=INNODB;
CREATE TABLE child(id INT, parent_id INT,
                      INDEX par_ind (parent_id),
                      FOREIGN KEY (parent_id) REFERENCES parent(id)
                      ON DELETE CASCADE
) TYPE=INNODB;

Created two records :
insert into parent values(5);
insert into child values(0,5);

Ok this works all fine. Also geives me errors when I give it a parent ID of
an unexisting record, so works like it should.

Now isn't the goal of ON DELETE CASCADE is that when the parent record is
deleted that the child records that reference the parent record id get
deleted aswell?

Because this doesn't seem to work. I get :
mysql> delete from parent where id=5;
ERROR 1217: Cannot delete a parent row: a foreign key constraint fails

Do I have the wrong idea baout the feature or what might be wrong?

Using Version 3.23.50-max-nt and InnoDB.


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to