User login

Change the vocabulary of a taxonomy term in Drupal 7 using the database

By clicking the wrong Add terms link, i managed to add a couple terms to the wrong vocabulary.

One of the powerful things about taxonomy is that all terms are really equals under the hood, no matter what vocabulary they belong to. Unfortunately, Drupal does not make this power available through the UI. We can, however,

We log into our server, log into MySQL via the command line, tell mysql to use the database we want to use, and run a simple update/set query. (In Agaric's server set-up courtesy Stefan Freudenberg, our key gets us into the server and our (server) user's automatically created .myconf file gets us into MySQL with the right permissions.) Like so:

ben@ubuntu:~/code/dgd7$ ssh definitivedrupal@sojourner.mayfirst.org
definitivedrupal@sojourner:~$ mysql
mysql> USE dgd7
mysql> UPDATE taxonomy_term_data SET vid = 4 WHERE tid = 22 OR tid = 23;
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2  Changed: 2  Warnings: 0

Background:

First, i got the lay of the land by running these queries:

mysql> SHOW TABLES;
mysql> SELECT * FROM taxonomy_index;
mysql> SELECT * FROM taxonomy_term_hierarchy;
mysql> SELECT * FROM taxonomy_term_data;
mysql> SELECT * FROM taxonomy_vocabulary;

This confirmed that the only place the vocabulary ID (stored as vid) was associated with a term is in the taxonomy_term_data table.

To Do: Make this into a module. Term Switch is an old 4.7/5.x module that does this. For some reason i thought i had one that did it in 6.x too...` (Nope, the name of the module is Taxonomy Switch and i helped upgrade it to Drupal 5.

Update: For taxonomy_switch capabilities in Drupal 6 and Drupal 7, see Taxonomy Manager and for Drupal 8 see the patch, which i just re-rolled, https://www.drupal.org/project/taxonomy_manager/issues/2799359#comment-12471072

Searched words: 
term switch Drupal taxonomy mysql SET

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.