title: Python MySQLdb: Inserting duplicate entry into a table with UNIQUE fields
body: <p>I have a MySQL database that contains a table named <code>commands</code> with the following structure:</p>
  
  <pre><code>+-----------+---------------+------+-----+---------+----------------+
  | Field     | Type          | Null | Key | Default | Extra          |
  +-----------+---------------+------+-----+---------+----------------+
  | id        | int(11)       | NO   | PRI | NULL    | auto_increment |
  | input     | varchar(3000) | NO   |     | NULL    |                |
  | inputhash | varchar(66)   | YES  | UNI | NULL    |                |
  +-----------+---------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>I am trying to insert rows in it, but only if the <code>inputhash</code> field does not already exist. I thought <code>INSERT IGNORE</code> was the way to do this, but I am still getting warnings.</p>
  
  <p>For instance, suppose that the able already contains</p>
  
  <pre><code>+----+---------+------------------------------------------------------------------+
  | id | input   | inputhash                                                        |
  +----+---------+------------------------------------------------------------------+
  |  1 | enable  | 234a86bf393cadeba1bcbc09a244a398ac10c23a51e7fd72d7c449ef0edaa9e9 |
  +----+---------+------------------------------------------------------------------+
  </code></pre>
  
  <p>Then when using the following Python code to insert a row</p>
  
  <pre><code>import MySQLdb
  
  db = MySQLdb.connect(host='xxx.xxx.xxx.xxx', user='xxxx', passwd='xxxx', db='dbase')
  c = db.cursor()
  c.execute('INSERT IGNORE INTO `commands` (`input`, `inputhash`) VALUES (%s, %s)', ('enable', '234a86bf393cadeba1bcbc09a244a398ac10c23a51e7fd72d7c449ef0edaa9e9',))
  </code></pre>
  
  <p>I am getting the warning</p>
  
  <pre><code>Warning: Duplicate entry '234a86bf393cadeba1bcbc09a244a398ac10c23a51e7fd72d7c449ef0edaa9e9' for key 'inputhash'
    c.execute('INSERT IGNORE INTO `commands` (`input`, `inputhash`) VALUES (%s, %s)', ('enable','234a86bf393cadeba1bcbc09a244a398ac10c23a51e7fd72d7c449ef0edaa9e9',))
  </code></pre>
  
  <p>Why does this happen? I thought that the whole point of using <code>INSERT IGNORE</code> on a table with <code>UNIQUE</code> fields is to suppress the error and simply ignore the write attempt?</p>
  
  <p>What is the proper way to resolve this? I suppose I can suppress the warning in Python with <code>warnings.filterwarnings('ignore')</code> but why does the warning appear in the first place?</p>