diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install
index f28ffed..51f50e1 100644
--- a/modules/taxonomy/taxonomy.install
+++ b/modules/taxonomy/taxonomy.install
@@ -199,6 +199,7 @@ function taxonomy_schema() {
         'default'=> 0,
       ),
     ),
+    'primary key' => array('nid', 'tid'),
     'indexes' => array(
       'term_node' => array('tid', 'sticky', 'created'),
       'nid' => array('nid'),
@@ -566,7 +567,7 @@ function taxonomy_update_7005(&$sandbox) {
   // of term references stored so far for the current revision, which
   // provides the delta value for each term reference data insert. The
   // deltas are reset for each new revision.
-  
+
   $conditions = array(
     'type' => 'taxonomy_term_reference',
     'deleted' => 0,
@@ -819,3 +820,45 @@ function taxonomy_update_7010() {
   ));
 }
 
+/**
+ * Add a primary key to the {taxonomy_index} table
+ */
+function taxonomy_update_7011() {
+  // Drop first: people might already have added a primary key themselves (e.g.
+  // to edit the table in MySql workbench), but with dfferent fields or order.
+  db_drop_primary_key('taxonomy_index');
+
+  // Remove possible duplicates.
+  // - Find the duplicates
+  $select = db_select('taxonomy_index', 'ti')
+    ->fields('ti', array('nid', 'tid', 'sticky'));
+  // We are going to re-insert the last created duplicate: max(created) expression
+  $max_alias = $select->addExpression('max(created)', 'max');
+  $count_alias = $select->addExpression('count(*)', 'count');
+  $select
+    ->groupBy('nid')
+    ->groupBy('tid')
+    ->havingCondition($count_alias, 1, '>');
+  $duplicates = $select->execute()->fetchAll();
+
+  if (count($duplicates) > 0 ) {
+    // - Build a "delete all duplicates" query.
+    $delete = db_delete('taxonomy_index');
+    $conditions = &$delete->conditions(); // Returns by reference,
+    $conditions['#conjunction'] = 'OR';  // so we can change it into an OR.
+    // - And build a "re-insert one of the duplicates" query.
+    $insert = db_insert('taxonomy_index')
+      ->fields(array('nid', 'tid', 'sticky', 'created'));
+    foreach ($duplicates as $duplicate) {
+      $delete->condition(db_and()
+        ->condition('nid', (int) $duplicate->nid, '=')
+        ->condition('tid', (int) $duplicate->tid, '='));
+      $insert->values(array($duplicate->nid, $duplicate->tid, $duplicate->sticky, $duplicate->$max_alias));
+    }
+    $delete->execute();
+    $insert->execute();
+  }
+
+  // And finally, add the primary key
+  db_add_primary_key('taxonomy_index', array('nid', 'tid'));
+}
