Update a field type with hook_update() My module provides config that creates a field:

field.storage.paragraph.field_accordion_section_title.yml

langcode: en
status: true
dependencies:
  module:
    - paragraphs
    - text
id: paragraph.field_accordion_section_title
field_name: field_accordion_section_title
entity_type: paragraph
type: text_long
settings: {  }
module: text
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false


I would like to update the field to use string_long instead of text_long.  I would like to handle this via hook_update() since the module was already installed on multiple sites.  I tried the following:

use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Updates accordion section title to string type.
 */
function my_module_update_8001() {
  if ($fields = \Drupal::entityTypeManager()-&gt;getStorage('field_storage_config')-&gt;loadByProperties(array('field_name' =&gt; 'field_accordion_section_title'))) {
    foreach ($fields as $field) {
      $new_field = $field-&gt;toArray();
      $new_field['type'] = 'string_long';
      $new_field = FieldStorageConfig::create($new_field);
      $new_field-&gt;original = $field;
      $new_field-&gt;enforceIsNew(FALSE);
      $new_field-&gt;save();
    }
  }
}


I get the following error when updating: Failed: Cannot change the field type for an existing field storage.
As the error message says, this is not supported. There is no API that will do it for you.

There was a similar question recently but I can't find it right now, just this one: How do I change the type of a field attached to a content entity?

In short, you have two options:


Create a new field, write a script to move over all your data, then delete the old field.
Manually alter the database schema and low-level config data as well as the data that Drupal has stored about the field type and its schema. This is by far the more complicated option.