title: MySQL - ON update CASCADE + foreign_key_checks = 0
body: <p>I am developing a tool to merge two databases with the same schema but different data.</p>
  
  <p>Part of it is changing all foreign keys to <code>ON UPDATE CASCADE</code>, then incrementing all the Primary Keys to avoid conflicts and keep foreign keys pointers working.</p>
  
  <p>My problem is that sometimes there are some orphaned rows with broken FK, so following query:</p>
  
  <pre><code>UPDATE table set pk = pk + 1000000
  </code></pre>
  
  <p>fails like this:
  <code>ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails</code>...
  (despite I'm not even thinking about touching foreign key column!)</p>
  
  <p>I wanted to turn that off by:</p>
  
  <pre><code>Set foreign_key_checks=0
  </code></pre>
  
  <p>but then related foreign keys are not updated. I've made a quick test and cascades are not working after setting foreign_key_checks=0.</p>
  
  <p>Is there any way to trigger cascades, or perform an update of a row with broken FK without setting <code>foreign_key_checks=0</code>? <code>UPDATE IGNORE</code> doesn't solve this problem :(</p>