Custom field storage, Per field How can I alter a field's storage property? What's the correct hook to use to alter $field['storage'] = 'my_custom_storage';?

I am currently using the global db variable field_storage_default but I find that to be gross. I don't want to do it for all fields.
I thought this can be done using hook_field_create_field, but it's not possible. Using that hook and then calling field_update_field will not work because the update does not allow this:

  if ($field['storage']['type'] != $prior_field['storage']['type']) {
    throw new FieldException("Cannot change an existing field's storage type.");
  }


Drupal doesn't want you to screw up existing data. So being careful and knowing what you are doing, the existing fields could be modified in the field_config table in the database. Reimplementing field_update_field you could do:

/**
* Implements hook_field_create_field().
*/
function mymodule_field_create_field($field) {
  if ($field['type'] == 'fieldtypetostore') {
    $field['storage'] = array(
        'type' =&gt; 'mymodule_custom_storage',
        'settings' =&gt; array(),
        'module' =&gt; 'mymodule',
        'active' =&gt; 1,
    );

    // Build record to update.
    $record = array(
      'id' =&gt; $field['id'],
      'storage_type' =&gt; $field['storage']['type'],
      'storage_module' =&gt; $field['storage']['module'],
      'storage_active' =&gt; $field['storage']['active'],
    );

    // Update the field storage.
    $primary_key = array('id');
    drupal_write_record('field_config', $record, $primary_key);
  }
}

/**
* Implements hook_field_update_field().
*/
function mymodule_field_update_field($field) {
  mymodule_field_create_field($field);
}


The best way to do this is to create the fields in your module that you need to use and at that time, set the storage for the field. It's cleaner than changing existing fields.