title: ERROR 1451: Cannot delete or update a parent row: a foreign key constraint fails
body: <pre><code>CREATE  TABLE `categories` (
    `idcategories` INT NOT NULL AUTO_INCREMENT ,
    `idparent` INT NULL ,
    `description` VARCHAR(45) NULL ,
    PRIMARY KEY (`idcategories`) );
  
  ALTER TABLE `categories` 
    ADD CONSTRAINT `FK_idparent`
    FOREIGN KEY (`idparent` )
    REFERENCES `ilmercatinodelpulcino`.`categories` (`idcategories` )
    ON DELETE CASCADE
    ON UPDATE CASCADE
  , ADD INDEX `FK_idparent` (`idparent` ASC) ;
  
  INSERT INTO `categories` (`idcategories`, `description`)
      VALUES (1, 'cat1');
  INSERT INTO `categories` (`idcategories`, `idparent`, `description`)
      VALUES (2, 1, 'cat1_child');
  </code></pre>
  
  <p>So this table represents a category, with an ID and a self pointing parent ID.
  I have inserted a category cat1 and a subcategory cat1_child with parent id of cat1.</p>
  
  <p>Now, I want to be able to change idcategory of cat1 from 1 to 10 and because I set the foreign key on update CASCADE, I expect that idparent of cat1_child will be set to 10 as well.
  But when I do:</p>
  
  <pre><code>UPDATE `categories` SET `idcategories`=10 WHERE `idcategories`='1';
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>ERROR 1451: Cannot delete or update a parent row: a foreign key
    constraint fails (<code>categories</code>, CONSTRAINT <code>FK_idparent</code> FOREIGN KEY
    (<code>idparent</code>) REFERENCES <code>categories</code> (<code>idcategories</code>) ON DELETE
    CASCADE ON UPDATE CASCADE) SQL Statement: UPDATE <code>categories</code> SET
    <code>idcategories</code>=10 WHERE <code>idcategories</code>='1'</p>
  </blockquote>
  
  <p>The delete instead work as expected and deleting cat1, cat1_child will be deleted as well.</p>
  
  <p>Where is the error?
  Than you.</p>