I cannot uninstall the field collection module cleanly (uninstall from Drupal, without using db sql query) even after removing all content types with field collection field defined. This is related to: #943772: field_delete_field() and others fail for inactive fields

Current proposed solutions - (as suggested in #943772: field_delete_field() and others fail for inactive fields):

When there is field data in place, there is a de-facto dependency of the field system as a whole on field type modules - if that module is disabled, it is has no idea what to do with the data until the module is re-enabled again (and other actions while the module is disabled, like deleting bundles or instances can complicate this too).

The current patch uses hook_system_info_alter() to make this dependency explicit - i.e. by making those field type modules required in the UI, with an explanatory note.

With the proposed solution, a module which both defines and implements a field type can not delete its fields on uninstall. Therefore, the solution is "Don't do that." Instead, the field type should be defined in a helper module which the implementation module depends on.
For example:

foo_field.module implements hook_field_info() to define a field type foo_type.
foo.module depends on foo_field.module.
When a user installs foo.module, foo_install() calls field_create_field(array('field_name' => 'foo', 'field_type' => 'foo_type')).
When the user uninstalls foo.module, foo_uninstall() calls field_delete_field('foo'), and its fields are marked for deletion.
The field values get purged on subsequent cron runs.
After the purge is completed, the user can uninstall foo_field.module.

Comments

Refineo’s picture

As a temporary solution I run sql query:
DELETE FROM `field_config` WHERE `field_config`.`deleted` = 1;

field_delete_field() only marks data as deleted. The actual deletion of values (calling the field type's hook_field_delete() on each), and of the $field and $instance definitions in the end, happen by small batches on cron (field_purge_batch() - not related to the Batch API).

So theoretically the field type module needs to be around for as long as there are still values to purge, so that we don't purge anything without the right hook_field_delete() being available. This takes an arbitrary amount of cron runs (the current UI provides no feedback at all regarding this).

(#943772: field_delete_field() and others fail for inactive fields)

mototribe’s picture

that worked great for me - thanks!!!

Refineo’s picture

Status: Active » Closed (won't fix)

@mototribe, I am glad this helped you.

I think, I will close this issue as the long term solution will come from the Drupal core fix in #943772: field_delete_field() and others fail for inactive fields.

decibel.places’s picture

Running Cron took care of this for me, on fields used by the Brightcove module, not the Field Collection module; presumably the cron hook processes fields marked for deletion.

dwalker51’s picture

The sql in #1 did it for me, after running I could drush dis field_collection. thanks

g76’s picture

yep #1, thanks so much!

truyenle’s picture

#1 work for me too.

valderama’s picture

In addition to the field_config table you should also cleanup field_config_instance table and also delete the field_deleted_data and field_deleted_revision table(s).

Running cron and hope that field_purge_batch takes care of deletion did not work in my case. I have entity_translation enabled - maybe that disturbs?

knowledges33ker’s picture

The query in #1 worked for me as well. Prior to running this we would get an error message any time we tried to delete a field and also errors when running cron.

Thanks @Refineo for the lead!!

ilgriso’s picture

#1 still needed, thanks so much!

kscheirer’s picture

#1 worked for me as well - none of the linked issues ever came to a resolution unfortunately. This issue ranks very highly in a google search for "drupal fields pending deletion", so it's become the solution most people use. Perhaps we could document this somewhere a little nicer, and get out of individual module queues?

Bowevil’s picture

#1 worked for me. I was having issues with addressfield and I could not uninstall that module. +1 karma to Refineo

kopeboy’s picture

#1 I got this: #1146 - Table 'myDatabaseXXX.field_config' doesn't exist

???

giupenni’s picture

#1 works for me...thank you!!!

iphan’s picture

#1 did not work for me. "select * from field_config where deleted=1;" returned an empty set. Same for field_config_instance. I have no table that start with 'field_deleted...'

Uninstall field collection still fails with Required by: Drupal (Field type(s) in use - see Field list). The Field list shows nothing related to field collection.

This fixed it: https://www.drupal.org/node/1867134#comment-8574053