I migrated my site from lower version of drupal, during migration process the machine name of my vocabularies was changed, now I want to modify them manually, but I cant find the proper table in database. now the question is :

How can I edit vocabularies machine name manually?

3 Answers 3


Suppose that the machine name of your vocabulary is: test.

Then you can use the following code

$vid= 'test';

$vocabulary= taxonomy_vocabulary_load($vid);

$vocabulary->set('name', trim('newmachinename'));


change the newmachinename by your machine name.

Note. you must be careful when using this code, because those configurations that you have with the previous machine name will be affected

  • Will this break any configuration that already points to the old machine name? If so, you should warn about that. Commented Nov 30, 2017 at 3:44
  • is correct, but since he is in the process of migrating the data, we assume that he is not referring to the old name machine. Commented Nov 30, 2017 at 10:47
  • My understanding of the question is that the migration is over, which means the migration process may have moved other things (views, etc.) to use the new machine name. Commented Nov 30, 2017 at 10:48
// Create new vocabulary.
$vid = 'site_press_centre';
$name = 'News';
$vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
if (!isset($vocabularies[$vid])) {
  $vocabulary = \Drupal\taxonomy\Entity\Vocabulary::create(array(
        'vid' => $vid,
        'name' => $name,

// Update current terms.
$vid_old = 'press_centre';
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vid_old);
$tids = $query->execute();
foreach ($tids as $tid) {
    $term = \Drupal\taxonomy\Entity\Term::load($tid);
    if (!empty($term)) {
      $term->vid = $vid;

// Delete old vocabulary.
$vocabulary = \Drupal::entityTypeManager()->getStorage('taxonomy_vocabulary')->load($vid_old)->delete();

Just to round this question up, if you do have access to the migration YAML files, you can already set the new vocabulary names during the migration.

      plugin: make_unique_entity_field
      source: machine_name
      entity_type: taxonomy_vocabulary
      field: vid
      length: 32
      migrated: true
      plugin: forum_vocabulary
      machine_name: forums
      plugin: static_map
        vocabulary_1: new_vocab_1
        vocabulary_2: new_vocab_2
        vocabulary_3: new_vocab_3
      bypass: TRUE

The last plugin in the chain allows you to rename machine names of vocabularies, in the above example, these are originally Drupal 6 names (vocabulary_X) which where now transferred into proper vocab names.

The bypass: TRUE allows the migration to leave any other machine name that is not in the list to remain untouched. The opposite would be to set a default value, which will be returned instead if the name is not in the list.

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.