title: Deleting a row with a self-referencing foreign key
body: <p>I have a MySQL table whose definition is as follows:</p>
  
  <pre>
  CREATE TABLE `guestbook` (
    `Id` int(10) unsigned NOT NULL,
    `ThreadId` int(10) unsigned NOT NULL,
    PRIMARY KEY (`Id`),
    KEY `ThreadId` (`ThreadId`),
    CONSTRAINT `guestbook_ibfk_1` FOREIGN KEY (`ThreadId`) REFERENCES `guestbook` (`Id`)
  ) ENGINE=InnoDB;
  </pre>
  
  <p>and currently there's only 1 row in the table:</p>
  
  <pre>
  mysql> select * from guestbook;
  +-----+----------+
  | Id  | ThreadId |
  +-----+----------+
  | 211 |      211 |
  +-----+----------+
  </pre>
  
  <p>The problem is that there's no way to delete this row without breaking the constraint.</p>
  
  <pre>
  mysql> delete from guestBook;
  ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`polaris`.`guestbook`, CONSTRAINT `guestbook_ibfk_1` FOREIGN KEY (`ThreadId`) REFERENCES `guestbook` (`Id`))
  </pre>
  
  <p>As the ThreadId column was defined not null, it is also impossible to set the ThreadId to a different value temporarily to delete the row. Is there a way to delete the row without changing the definition of the table or dropping the entire table?</p>