0

To manually remove a taxonomy vocabulary in the database, what tables/columns etcetera do I need to delete or modify?

I have a "ghost" taxonomy - it shows up in the list, but doesn't exist anywhere else. I cannot edit it through the website admin - it says page doesn't exist. I can't delete it by using drush entup

But I must remove this somehow, as it's disrupting the website with errors...

LogicException: Missing bundle entity, entity type taxonomy_vocabulary, entity id Regions

As a hook_update_n solution didn't work, and installing a module to do 'drush entup' didn't work... where can I remove this from the database? I had the team in charge of the database itself do a search and pull this result:

Database search for 'Regions'

I'm assuming that first result is for the block structure, and unrelated to my taxonomy. But maybe someone sees an issue with the results below it, or if we can safely delete those to get rid of this 'ghost' taxonomy?

2 Answers 2

1

From the world of weird solutions that work...

  • I tried using a module and 'drush entup' ... didn't work
  • I tried creating a module to use 'hook_update_N' to delete it ... didn't work
  • I tried using hook_update_N to Create it, so I could then delete it ... didn't work.

On a whim, I went to the admin page, listing taxonomies. I dragged the 'ghost' taxonomy to rearrange the list. Then I saved. Suddenly, all the options to edit it had returned. I was finally able to delete the taxonomy using the usual dropdown field.

0

Take any existing custom module or create one and install it. Then let this module have an .install file and in there implement hook_update_N with the following code to delete the vocabulary when you run database updates the next time, for example via $ drush updb.

<?php

use Drupal\taxonomy\Entity\Vocabulary;

/**
 * Delete vocabulary MY_VOCABULARY.
 */
function MYMODULE_update_8101(&$sandbox) {
  $vid = 'MY_VOCABULARY_MACHINE_NAME';
  $vocabulary = Vocabulary::load($vid);
  if ($vocabulary) {
    $vocabulary->delete();
  }
}
6
  • Ran into some errors and this broke the site. Waiting for team-member to restore last backup.. but got "syntax error, unexpected '$vocabulary' (T_VARIABLE)" maybe it's just missing the semicolon at the ned of that $vid variable line? Are there other issues that may have caused trouble? For reference my taxonomy vocab. is called "Regions"
    – turpentyne
    Commented Aug 21, 2019 at 23:56
  • There was a missing semicolon. No need to restore. Just add the semicolon and flush caches $ drush cr. Are you doing this on live? Always do this on a local copy of the site first. The vocabulary machine name probably is regions then.
    – leymannx
    Commented Aug 22, 2019 at 5:53
  • Ok.. added the semicolon, flushed cache, double checked machine name, and entered "drush updb". All I got was "[success] no pending updates." I tried with capital R & without. When I look at the taxonomies page, my ghost taxonomy 'Regions' is still listed. I have: code function custom_node_delete_update_8101(&$sandbox) { $vid = 'regions'; $vocabulary = Vocabulary::load($vid); if ($vocabulary) { $vocabulary->delete(); } } code
    – turpentyne
    Commented Aug 22, 2019 at 16:01
  • Increment the number. 8101, 8102, 8103 etc.. Each time you run updb the number gets stored and won't be rerun again.
    – leymannx
    Commented Aug 22, 2019 at 16:33
  • Ah.. I understand now.. Unfortunately, it still is not clearing it out. I'm thinking I may just need to go into the actual database and physically delete entries. But I don't know where, because I'm sure it would be in multiple areas.
    – turpentyne
    Commented Aug 22, 2019 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.