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
Comments
Post new comment