0

In a custom module, I'm creating a new field and instance for a custom entity type like this:

function mymodule_install() {
  if (!field_info_field('mymodule_field')) {
    $field = array( .... );
    field_create_field($field);
  }
  if (!field_info_instance('mymodule_entity','mymodule_field', 'bundle1')) {
    $instance = array( .... );
    field_create_instance($instance);
  }
}

function mymodule_uninstall() {
  if ($instance = field_info_instance('mymodule_entity','mymodule_field', 'bundle1')) {
    field_delete_instance($instance);
  }
  if (field_info_field('mymodule_field')) {
    field_delete_field('mymodule_field');
  }
  field_purge_batch(100);
}

...and the field and instance gets created properly. However upon uninstalling the module, only the field tables are being deleted while the field instance is still there in the field_config_instance table still having deleted = 0.

Debugging the uninstall process reveals that field_info_instance (and field_read_instances) is returning NULL...

Anyone knows what I'm doing wrong? I'm on a fresh Drupal 7.23 install...

0

You don't need field_delete_instance separately, because field_delete_field has it inside.

According to deleted column in field_config (you can skip this value in field_config_instance if you're deleting whole field) debug field_delete_field function.

  • field_delete_field() still doesn't delete the entry in the field_config_instance table... – Propaganistas Nov 20 '13 at 11:42
  • field_config_instance entry will be removed only after all field_data_ and field_revision_ entries are deleted. May be your batch size in purge is not big enough. Check the deleted column in field_config, field_config_instance and names of deleted field tables to be sure that field_delete_field was completed successful. – m1r1k Nov 20 '13 at 13:11
  • The field tables are deleted successfully and also their entry in field_config is completely removed. The purging function is doing well.. However field_config_instancestill contains the instance entries with deleted = 0.. – Propaganistas Nov 20 '13 at 13:58
  • Try to run drush cron manually now, it should get cleared otherwise you have a trouble somewhere :) – m1r1k Nov 20 '13 at 14:11
  • Unfortunately no luck. Well, I guess my OP still remains unsolved. Quite odd since it's on a fresh 7.23 install. – Propaganistas Nov 20 '13 at 14:25

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.