Can't disable module when it defines an field type used by a custom entity I have created a module that creates a custom entity (using hook_entity_info etc.), defines a field type (using hook_field_schema and hook_field_info), and then creates an instance of the field type with my custom entity (using field_create_field and then field_create_instance).

This all works great until I try to uninstall the module and am told "Drupal (Field type(s) in use".

Whilst this is true they won't be in use once the module is uninstalled!

Short of going into the DB and starting to delete rows out of the field_config and field_config_instance table how do I get round this problem?

Here I am creating the field instance in hook_enable:

function emtr_enable() {

    field_cache_clear();
    field_associate_fields('emtr');

    if(field_info_field('emtr_denominations')) return;

    $field = array(
        'field_name' =&gt; 'emtr_denominations',
        'type' =&gt; 'field_emtr_denominations',
        'cardinality' =&gt; FIELD_CARDINALITY_UNLIMITED,
        'translatable' =&gt; FALSE,
    );
    field_create_field($field);

    $instance = array(
        'field_name' =&gt; 'emtr_denominations',
        'entity_type' =&gt; 'emtr_safe_check',
        'bundle' =&gt; 'emtr_safe_check',
        'label' =&gt; 'Denominations',
        'required' =&gt; false,
        'widget' =&gt; array(
            'type' =&gt; 'number'
        ),
        'settings' =&gt; array(
            'target_type' =&gt; 'emtr_safe_check',
            'handler_settings' =&gt; array('target_bundles' =&gt; NULL),
        ),
        'display' =&gt; array(
            'default' =&gt; array('label' =&gt; 'inline', 'type' =&gt; 'number_integer'),
        ),
    );
    field_create_instance($instance);
}


And here is my uninstall hook:

function emtr_uninstall() {
    if ($instance = field_info_instance('emtr_safe_check', 'emtr_denominations', 'emtr_safe_check')) {
        field_delete_instance($instance);
    }
    if (field_info_field('emtr_denominations')) {
        field_delete_field('emtr_denominations');
    }
    field_purge_batch(100);
}


And hook_field_schema:

/**
 * Implements hook_field_schema
 */
function emtr_field_schema($field) {

    $columns = array(
        'denomination_value' =&gt; array(
            'type' =&gt; 'int',
            'not null' =&gt; FALSE,
        ),
        'denomination_tid' =&gt; array(
            'type' =&gt; 'int',
            'not null' =&gt; TRUE,
            'default' =&gt; 0,
        ),
    );
    $indexes = array(
        'denomination_tid' =&gt; array('denomination_tid'),
    );
    return array(
        'columns' =&gt; $columns,
        'indexes' =&gt; $indexes,
    );
}


Just in case my hook_field_info and hook_entity_info are in a pastebin here.
So as Clive suggested I solved this by creating a helper module called emtr_fields.

The emtr_fields module creates the entity and has the field schema.

Then the main emtr module creates the field and it's instance.

To remove all of this again first the emtr module has to be disable AND uninstalled (it has to be uninstalled as the field and it's instance is deleted in hook_uninstall), and then the emtr_field module can be disabled and uninstalled.

I also found some documentation on this on drupal.org here:

Module cannot be disabled because Drupal claim "Field type(s) in use"

Moving field(s) definitions into a separate module of a installed module.

Field types should be defined by one module and implemented by a separate module.