title: How to update foreign key value in mysql database
body: <p>I have three tables: categories, languages and categories_languages. Categories_languages is many to many table which links together categories and languages. I would like to update a foregin key value in table languages but it throws me error #1451 - Cannot delete or update a parent row: a foreign key constraint fails! </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `categories` (
    `id` int(11) unsigned NOT NULL auto_increment,
    `name` varchar(20) NOT NULL,
    `modified` int(10) unsigned NOT NULL,
    PRIMARY KEY  (`id`),
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
  
  CREATE TABLE IF NOT EXISTS `languages` (
    `id` char(2) NOT NULL,
    `name` varchar(20) NOT NULL,
    PRIMARY KEY  (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
  CREATE TABLE IF NOT EXISTS `categories_languages` (
    `id` int(11) unsigned NOT NULL auto_increment,
    `category_id` int(11) unsigned NOT NULL,
    `language_id` char(2) NOT NULL,
    `translation` varchar(20) NOT NULL,
    PRIMARY KEY  (`id`),
    KEY `fk_category_id_language_id` (`category_id`,`language_id`),
    KEY `fk_language_id` (`language_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;
  
  ALTER TABLE `categories_languages`
    ADD CONSTRAINT `categories_languages_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE,
    ADD CONSTRAINT `categories_languages_ibfk_2` FOREIGN KEY (`language_id`) REFERENCES `languages` (`id`) ON DELETE CASCADE;
  </code></pre>
  
  <p>The error is clear to me, but how can I update a key value in this case? I tried adding ON UPDATA CASCADE:</p>
  
  <pre><code>ALTER TABLE `categories_languages`
    ADD CONSTRAINT `categories_languages_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `categories_languages_ibfk_2` FOREIGN KEY (`language_id`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
  </code></pre>
  
  <p>but that also fails with message: MySQL said: Documentation #1005 - Can't create table './db_dodo/#sql-c2f_80e6f.frm' (errno: 121)</p>