When i try to add a content item to multiple categories housed in different containers, i get the following errors...

user warning: Duplicate entry '1-31' for key 1 query: INSERT INTO term_node (nid, tid) VALUES (31, 1) in /srv/www/htdocs/sandbox/drupal/includes/database.mysqli.inc on line 151.

My setup is simple, i have 2 containers each with a number of categories. I want to create a content item that is a member of any number of categories from each container. So i select 1 category from each container on the content creation page, and i get that error upon submission. Any ideas?

Comments

richardfullmer’s picture

The offending code was in the taxonomy.module file starting on line 561

 if (is_array($terms)) {
      foreach ($terms as $key => $term) {
        if ($key != 'tags' && $key != 'legacy') {
          if (is_array($term)) {
            foreach ($term as $tid) {
              if (!empty($tid)) {
                db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $tid);
              }
            }
          }
		  // OLD VERSION - SEE BELOW
		  //else if (isset($term->tid)) {
          //  db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term->tid);
          //}		  
		  // NEW VERSION		  
          else if (isset($term->nid)) {
            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term->nid);
          }
		  // END NEW VERSION
          else if ($term) {
            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term);
          }
        }
      }
inforeto’s picture

Marking as duplicate of http://drupal.org/node/115783
There's more reports of "duplicate entry" issues in the queue.

sjh-1’s picture

I've just been battling the same issue, and came up with a fix in http://drupal.org/node/87669#comment-225000 The idea of my fix is to make the taxonomy structure to actually include the tid field, rather than instead use the nid field as your fix has it.

bdragon’s picture

Status: Active » Closed (duplicate)

Marking as duplicate of http://drupal.org/node/87669.

Thank you for your report.
--Brandon