1

Problem

I have a taxonomy field that I was forced to re-create with different values after a number of errors. (I deleted the field and taxonomy and re-created them.)

It's used as an exposed filter in views and unfortunately appears to have become corrupted. Whenever I use it as a filter, in the drop down it only shows the previous values of the field (before it was re-created).

Clearing the cache, re-creating the field, clearing the search indexes, creating new views have all had no effect. Other identical field names with different machine names work fine so I'm presuming it's corrupted.

How should I go about cleaning this field from my database?

I'm considering just re-making it under a different name but I'm worried about the consequences of leaving some corruption in my database.

  • Database restore from backup is not an option? – Mołot Jan 15 '14 at 14:30
  • 1
    I have a second problem with a Search API bug which appears to exist on every backup I've had for the past 3 months. The two seem to be linked in some horrible way. I'm also trying stuff from a backup, but I was wondering what other options I might have. – Dominic Woodman Jan 15 '14 at 14:48
1

This is totally off the top of my head so use with much caution, and after taking lots of backups!

// Remove taxonomy index records. Do this BEFORE removing field data tables.
$indexed_tids = db_query("SELECT field_foo_tid FROM field_data_field_foo WHERE entity_type = 'node' AND bundle = 'bundle_field_is_attached_to'")->fetchCol();
db_delete('taxonomy_index')->condition('tid', $indexed_tids)->execute();

// Remove the field data tables completely
db_drop_table('field_data_field_foo');
db_drop_table('field_revision_field_foo');

// Remove the field config
db_delete('field_config')->condition('field_name', 'field_foo')->execute();
db_delete('field_config_instance')->condition('field_name', 'field_foo')->execute();

// Clear up
drupal_flush_all_caches();

That should get tid of a taxonomy field called field_foo, and all associated index data.

Note this is for a core install - if you have other modules installed that rely on that field or taxonomy data in some way, things might not be so easy.

  • Forgive the ignorance, how would you normally run this? My instinct is saying stick <php> around it and run it with drush php-script. – Dominic Woodman Jan 16 '14 at 13:31
  • Sorry @DominicWoodman, I missed that comment first time round. For adhoc scripts Drush is great, I usually just dump it in at /devel/php and push go – Clive Jan 28 '14 at 19:22
  • No problem, I got it sort of working, did use drush in the end. Unfortunately still getting one or two errors but I ran out of time. Hopefully I'll get some time in the future to come back update this with how I eventually solved it (when I solve it. Which I hopefully will.). – Dominic Woodman Jan 28 '14 at 19:27

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.