diff --git modules/system/system.install modules/system/system.install
index 36387a1..29d0000 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -1212,6 +1212,9 @@ function system_update_6001() {
   db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid'));
   db_add_index($ret, 'term_node', 'vid', array('vid'));
 
+  // Remove nids from term_node that are not in the node table, or
+  // the update query fails and all terms are lost in system_update_6044().
+  db_query('DELETE FROM {term_node} WHERE nid NOT IN (SELECT nid FROM {node})');
   db_query('UPDATE {term_node} SET vid = (SELECT vid FROM {node} n WHERE {term_node}.nid = n.nid)');
   return $ret;
 }
