title: "Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry" error where index is truncated
body: <p>I sometimes get the following error in my application log for an insert into MySQL:</p>
  
  <pre><code>2013/06/02 15:11:05 (Database) Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4d9acbacc6ed7dc2733025e4b8af7be4940fe5b70338789b34caea27695860fa' for key 'hash_UNIQUE'
  </code></pre>
  
  <p>The problem with the above is that the value being indexed is being truncated to 64 characters long, but the actual column size 255 characters long.  An example of that value is: <code>4d9acbacc6ed7dc2733025e4b8af7be4940fe5b70338789b34caea27695860fa2b497f6cd34851657c9d3e8e8e88713d80da1a22d8654cf98622e9af3f29481d</code>.</p>
  
  <p>The table definition is below:</p>
  
  <pre><code>delimiter $$
  
  CREATE TABLE `reset` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `identity_id` bigint(20) unsigned NOT NULL,
    `hash` varchar(255) NOT NULL,
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `upn` varchar(255) NOT NULL,
    `returnurl` varchar(255) DEFAULT NULL,
    `processed` char(1) DEFAULT 'N',
    `referer` varchar(15) DEFAULT 'CPCUsociety.org',
    PRIMARY KEY (`id`),
    UNIQUE KEY `hash_UNIQUE` (`hash`),
    KEY `reset_upn_ndx` (`upn`),
    KEY `reset_hash_ndx` (`hash`),
    KEY `reset_timestampndx` (`timestamp`),
    KEY `idendity_id_for_key_idx` (`identity_id`),
    CONSTRAINT `idendity_id_for_key` FOREIGN KEY (`identity_id`) REFERENCES `identity` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  ) ENGINE=InnoDB AUTO_INCREMENT=585 DEFAULT CHARSET=utf8$$
  </code></pre>
  
  <p>How can I force MySQL to use the full value as the index? </p>