Posted on: Wednesday, 12 January 2011 @ 11:34pm
Blatting about
Came across a problem someone else on Drupal dubbed "ghost field" in one of the issue queues. My issue with ghost fields came about while setting up Profile2 to use in my profile (strangely), but the problem happens in other modules as well.
The problem
- create a profile type (or modify the main one)
- add a field
- delete the field (I don't recall seeing any difference between saving data in the field or not)
- try to add a new field with the same name, get an error saying the field name is already in use, but it doesn't appear in the "Add existing field" list
The solution
- manually edit the database. I use phpmyadmin. Whatever works
- find the tables field_config and field_config_instance, browse them and delete all incidences of the "ghost fields"
- fields can now be recreated
After deleting the ghost field instances the php fatal error and associated debug messages I'd been having trouble tracking the source of (Entity was getting blamed) disappeared, quite conveniently.
No comments yet
I had a weird variant of this problem, where the field_config and field_config_instance tables were fine (no mention of my ghost fields), but the field tables themselves still existed. In this case, it's apparently important to drop both the field_data_field_NAME table and the field_revision_field_NAME table.
Thanks, helped to uninstall a module with an "used" field
Thank you!
Another solution(The Drupal Way?) is to place field_delete_field('fieldname'); into index.php right after bootstrap. According to documentation this will mark the field and its instances and data for deletion.
I wouldn't count index.php as core but everyone can have their opinion.And getting your hands dirty while manually deleting data from db seems more hackish to me than using Field API from index.php. In the end, using the API will ensure that everything is done "by the book" and no related or otherwise dependent data is left over. Otherwise there might be more "hacking" to do.However, my solution came up when the site was down(install/uninstall failed) and certain fields seemed to be causing problems. So the solution was one line, one function and no hassle :) But as I said, everyone can do it their own way.
Thanks!
If anyone's wondering how to finally purge the fields marked for deletion -- field_purge_batch()http://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/function/field_purge_batch/7
Oh, it gets run on cron, so you might just want to do that manually. :) Sorry about the weird formatting in the previous message.
Running cron once doesn't always do the trick. If it doesn't work the first time, you may need to run cron 10 or 20 times to get the fields to actually be deleted. Its faster to just manually delete the two tables (field_data and field_revision) as well as the two records from field_instance and field_instance_config. Still not resolved as of the latest version of D7.
We just experienced the same thing. Field tables were in the database but the config tables didn't have any entries. Dropped the field_data and field_revision tables for these ghosties and all was fine. Issue was after using Feature to add a content type but not sure if that was the issue or not. Tried the feature again after and it worked.Prefer the sound of the API call in index.php perhaps but comfortable with restoring our DB (plenty of backups!) so was easy for us. thanks all!
The best "Drupal" way to do that would be to use drush field-delete {field-machine-name}. @see http://drush.ws/
Well, my mistake, you got to drop table manually
I'm having the same problem but even after I delete field_data_field_NAME table and the field_revision_field_NAME tables I still get the "Fields pending deletion" message on my modules page that prevents me from disabling the field collection module. I also get "WD cron: EntityFieldQueryException: Unknown field: field_name [error]" when I try to drush cron from the command line. Any ideas?
I kept reading about this and found the following post: https://drupal.org/node/1530812#comment-5865292 I ran the sql in comment #1 https://drupal.org/node/1530812#comment-5865292Specifically, I ran "
DELETE FROM `field_config` WHERE `field_config`.`deleted` = 1;"
This fixed my problem. Maybe it will help others also.Hi,I also had to run TRUNCATE cache_field because drush cc all still gave me the error. Thanks for the tips.
Thanks, that worked for me. Nasty.