Having trouble on a D6 -> D7 upgrade. Looked through all of the related bug reports / support requests on d.o, but didn't find a solution.

The error returned is:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'node-841-0-0-und' for key 'PRIMARY'

The offending insert is right here:

      // is_current column is a node ID if this revision is also current.
      if ($record->is_current) {
        db_insert($table_name)->fields($columns)->values($values)->execute();

I notice that is_current is set in this query:

SELECT td.vid AS vocab_id, td.tid, tn.nid, tn.vid, n.type, n2.created, n2.sticky, n2.nid AS is_current
FROM {taxonomy_term_data} td
INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid
INNER JOIN {node} n ON tn.nid = n.nid
LEFT JOIN {node} n2 ON tn.vid = n2.vid
ORDER BY tn.vid, td.weight ASC, tn.tid

Running that query myself and checking the offending NID provided by the PDOexception, I see the problem is that is_current is actually flagged twice: once with the actual nid of the content, and once again for a completely unrelated node:

taxonomy_update_7005 results

Possibly, my data is bad (this site went through a D5 -> D6 migration just over a year ago, possibly it's a problem with a contrib taxonomy-related module), but I think there's potentially a harmless fix. Patch attached.

Comments

btmash’s picture

I'm wondering if there is a way we can test this. And it does seem like some of the data did not exist though I am unsure why...which contrib taxonomy module did you have installed?

iamEAP’s picture

tac_lite, taxonomy manager, taxonomy super select, profile taxonomy, draggableviews_taxonomy, content_taxonomy, content_taxonomy_options, and i18n_taxonomy.

iamEAP’s picture

Not sure of the best way to test this; maybe the best way is to run devel generate in 6 and try upgrading? Not sure.

btmash’s picture

I'll give that a try once I can make some time for this (hopefully friday).

tmsimont’s picture

this function:

http://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.install/funct...

says:
@todo: This function can possibly be made much faster by wrapping a transaction around all the inserts.

I was upgrading 6.25 -> 7.14 and ran into a script timeout. i tried to re-run the update and got the error described here and over at http://drupal.org/node/1140746#comment-5065284

I boosted my php execution time to riculous levels, reverted my db, and re-ran update.. and it worked.

I don't have any taxonomy modules on the 6.x site, only taxonomy itself.

i do have 3 vocabularies, each with a ton of terms. each of my many nodes has multiple terms from each vocabulary. can you devel generate a really complex taxonomy to reproduce?

it sounds like if that @todo is taken care of, it might reduce the likelihood of this error?

drupalninja99’s picture

You will still have this line complain of dupes - db_insert($revision_name)->fields($columns)->values($values)->execute();

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.