0

I've created a couple of vocabularies programmatically, and accidentally included some spaces in the machine names (caused by bad data in an input CSV). I can't delete these vocabularies with Vocabulary::load($vid)->delete();, even though I can see the vocabularies names with
dsm(taxonomy_vocabulary_get_names());, while load($vid) returns NULL.

Any ideas on how I can delete these vocabularies? I was able to delete all the terms in a vocabulary, but the reference remains under admin/structure/taxonomy.

2
  • 2
    I assume you tried to delete them via the UI? – sonfd Jul 27 '20 at 16:58
  • I did. It seemed to partially delete the vocabulary and left it in an unstable state – A Stanley Jul 28 '20 at 18:31
1

Where are you calling that code? Is the $vid really right? You say it has spaces in it? Did you try to delete them from the UI?

Under /admin/structure/taxonomies where you have all vocabularies listed, open the operations dropdown and click "Edit vocabulary".

enter image description here

On the next page click "Delete".

enter image description here

1

Try to delete it from UI if that doesn't work. Install devel_generate module which is included in devel module as a sub module and select option to generate vocabulary and give count as 0. Don't forget to select delete existing vocabulary. It will delete existing vocabulary which will solve your problem.

1

To clarify - deleting the vocabulary through the UI allowed some of the menu choices, but not others.

I fixed it by doing a database dump and edited the dump with a search and replace (my vocabulary to my_vocabuary) and then importing the edited dump before deleting with the UI.

Not an elegant solution, but it worked.

1
  • did you try with devel_generate , If I remember correctly I was have similar issue and got resolved by it. – miststudent2011 Jul 29 '20 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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