Deleting the taxonomy field from the content type didn't remove the taxonomy terms from the nodes. Therefore, I wrote a PHP script to generate MySQL code to programmatically delete the terms after removing the taxonomy field from the nodes via the admin menu.
<?php
// put your database name here
$database = '';
// put your vocabulary table suffix here
// will be appeneded to table names like `field_data_taxonomy_` and `field_revision_taxonomy_`
$vocabulary = 'vocabulary_2';
$connection = mysql_connect(HOST, USER, PASS);
$nids = array();
$fp = fopen('taxonomy_clean.sql', 'w');
if (!$connection)
{
echo 'Unable to connect to database: ' . mysql_error();
exit;
}
if (!mysql_select_db($database))
{
echo 'Unable to select ' . $database . ': ' . mysql_error();
exit;
}
// get nid from all nodes except story type
$result = mysql_query('select * from ' . $database . '.node where type != \'story\' order by nid asc;');
while ($row = mysql_fetch_assoc($result))
{
$nid = $row['nid'];
$nids[] = $nid;
}
echo PHP_EOL, count($nids), ' nids', PHP_EOL;
// remove the taxonomy terms from the nodes
$taxonomy_index = 'DELETE FROM ' . $database . '.taxonomy_index WHERE nid IN (' . implode(',', $nids) . ');';
$field_data_taxonomy_vocabulary = 'DELETE FROM ' . $database . '.field_data_taxonomy_' . $vocabulary . ' WHERE entity_id IN (' . implode(',', $nids) . ');';
$field_revision_taxonomy_vocabulary = 'DELETE FROM ' . $database . '.field_revision_taxonomy_' . $vocabulary . ' WHERE entity_id IN (' . implode(',', $nids) . ');';
// write the MySQL script to disk
fwrite($fp, $taxonomy_index . PHP_EOL . PHP_EOL);
fwrite($fp, $field_data_taxonomy_vocabulary . PHP_EOL . PHP_EOL);
fwrite($fp, $field_revision_taxonomy_vocabulary . PHP_EOL . PHP_EOL);
fclose($fp);
?>
The script worked fine with PHP 5.4, and will generate taxonomy_clean.sql
. I used mysql
via the command line to run taxonomy_clean.sql
. I cleared the cache after and everything worked fine.