How to re-create vanilla field configuration strings programmatically for any field? After a D7 update and migration of fields, most of our problems with converted fields result from invalid or incompatible field settings. Field settings are stored in the
field_config_instance.data column in the database as serialized php objects.

How can I, for any given field instance, generate a fresh field configuration string, as if the field was just created in D7, while leaving the already stored field data intact?

My manual approach seems to work but is very cumbersome:


create a new content type
add an existing field to the new content type, generating new settings string
search the new and old field in the database
using sql: replacing the string in the data column of the old field (with the same name) with the new data content.


There must be a way to automate this a bit.
I guess you will need a combination of field_update_field() and field_create_field().

During field_create_field(), the settings are loaded from the default field definition as each field has defined in its own hook_field_info().

$field['settings'] += field_info_field_settings($field['type']);


What you are looking for is to apply this logic to field_update_field().

Basically you will need to load all fields:

$fields = field_info_fields();


Optionally limit the fields to your selection:

foreach ($fields as $field_name =&gt; $field) {
  if ($field['type'] == 'some type') {} // Filter by type
  if ($field_name == 'some name') {} // Filter by name
}


And update the fields:

$field['settings'] = field_info_field_settings($field['type']);
field_update_field($field);


So I guess it should look something like this:

$fields = field_info_fields();
foreach ($fields as $field_name =&gt; $field) {
  if ($field['type'] == 'some type') {
    $field['settings'] = field_info_field_settings($field['type']);
    field_update_field($field);
  }
}