title: Adding Composite Unique key and Duplicate Entry error
body: <p>In a pivot table I need to add composite unique key on two big-int fields.</p>
  
  <pre><code>ALTER TABLE table_name ADD UNIQUE KEY `uk_field1_field2` (field1, field2);
  </code></pre>
  
  <p>The query reports error</p>
  
  <pre><code>Duplicate entry '24014-1435' for key 'uk_field1_field2'
  </code></pre>
  
  <p>This is the last record in the table with these values I what guess form '24014-1435'. I have confirmed that combination is unique. If I remove that particular record, the error then points to second last row with the same error. Until I flush all the records, I cannot add unique key.</p>
  
  <p>Can I add unique key constraints on table without flushing all rows?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Table: table_name<br>
  Columns:<br>
  id  bigint(20) UN AI PK<br>
  created_at  timestamp<br>
  updated_at  timestamp<br>
  applied_at  timestamp<br>
  field1  bigint(20)<br>
  field2  bigint(20)<br>
  field3  bigint(20)<br>
  status  varchar(64)  </p>
  
  <p>Example Data</p>
  
  <pre><code>'2214', '2016-01-05 13:51:03', '2016-01-05 13:51:03', '2016-01-05 13:51:02', '1972', '24', '1155', 'applied'
  '2215', '2016-01-05 13:51:05', '2016-01-05 13:51:05', '2016-01-05 13:51:03', '1972', '31', '2137', 'applied'
  '2216', '2016-01-05 13:51:06', '2016-01-05 13:51:06', '2016-01-05 13:51:05', '1972', '33', '2487', 'on-hold'
  '345', '2016-01-05 08:50:07', '2016-01-05 08:50:07', '2016-01-05 08:50:07', '1717', '54', '4602', 'on-hold'
  </code></pre>