I have a number of categories that are defined in text files and I would like to avoid manually entering them through the web interface for multiple installations of Drupal. For example, lets day the vocabulary is fruit and I have a text file with apple, bananna, cherry, grape, etc in it. What I would like to do is convert this text file into mysql commands and add the categories using phpMyAdmin or command line mysql. What I am uncertain about the schema used by Drupal and in particular which tables would be effected by the addition of new vocabulary and categories. I assume the tables vocabulary, vocabulary_node_types are involved but uncertain what other tables (if any) may be effected by the addition of new categories.

Does anyone know how to construct the precise mysql commands to enter a new fruit vocabulary with categories apple, bananna, cherry, grape?

Comments

trevelyan’s picture

I should preface this by comment that I'm not terribly familiar with the way that drupal handles its own addition/deletion of vocabulary/terms, so do not know if this is the ideal way of doing things, but I have had to deal with batch file processing and the automatic creation/addition of nodes by php scripts, and use the following method which seems to work. Please note that I've been messing directly with MySQL only AFTER manually creating the vocabulary and adding terms using the engine.

Anyway, if you use MySQL to look at the two tables term_data and term_node (DESCRIBE term_data) things are pretty clear. The table term_data contains a list of terms identified with a tid (term ID). The table term_node contains only two items: tid (term ID) and nid (node ID). You can (apparently) tag nodes with terms simply by creating an entry in term_node which associates the nid of the node you want to tag with the tid of the appropriate entry in the term_data table.

To tag a node with more than one term, provide more than one entry in this table.