I have a multi-value text-field, projects. Its length is 4, and I would like to increase it to 255, but there are values saved in the database for that field.

How can I increase its length?

  • 4
    backup, export field's db table, delete field, clear the cache, create same field with 255, import, clear the cache.
    – No Sssweat
    Commented Sep 10, 2017 at 7:41
  • In my case, to import the previously backed-up content into the newly created table (when you create the same field again with the new character length), I had to open up the exported sql and only select the INSERT INTO part with all its values and paste that into the SQL query box in phpMyAdmin. Because simply importing that previously exported table using the Import function/tab gave an error saying that it could not create the table again, logically.
    – BassPlaya
    Commented Feb 15, 2020 at 1:08

5 Answers 5


I got an answer from my friend as well. I would like to share his code here:

 * Update field.
function MODULE_update_8301() {
  $db = \Drupal::database();
  $field_name = 'field_MY_TEXT_FIELD';
  $table_prefixes = [
  foreach ($table_prefixes as $table_prefix) {
        'type' => 'varchar',
        'length' => 255,
        'default' => '',

  $config = \Drupal::configFactory()->getEditable('field.storage.node.' . $field_name);
  $settings = $config->get('settings');
  $settings['max_length'] = 255;
  $config->set('settings', $settings);
  • 4
    I strongly against this solution. You shouldn't manipulate the fields by yourself. Do this via Drupal API.
    – ssibal
    Commented Sep 11, 2017 at 8:40

The schema of a field is not changeable until it has data inside. There can be many scenarios like you have multiple languages, or revisions are important etc, but the following steps can be an abstract approach of the situation:

  1. Keep in memory (variable) or save all the field values, which host field you are about to manipulate
  2. Delete your old field and import the new one (you can do it based on the YML file itself)
  3. Backup all the information with help of the EntityTypeManager.

This is indeed an advanced part of Drupal, but once you master it, updates like this will work like charm.


I tried the answer of asrob, but it doesnt work with entity update (drush entup).

There is a better solution using Drupal API. The code is from here: https://coderwall.com/p/uyidlq/updating-the-storage-definition-of-entities-that-already-have-content-in-drupal-8

 * Increase FIELD size to 50.
function MODULE_update_8XXX() {
  $database = \Drupal::database();
  // Retrieve existing field data.
  $entity_type = 'ENTITY_TYPE';
  $field = 'FIELD_NAME';
  $tables = [
  $existing_data = [];
  foreach ($tables as $table) {
    // Get the old data.
    $existing_data[$table] = $database->select($table)

    // Wipe it.

  $field_storage_configs = \Drupal::entityTypeManager()
      'field_name' => $field,
  foreach ($field_storage_configs as $field_storage) {
    $new_field_storage = $field_storage->toArray();
    $new_field_storage['settings']['max_length'] = 50;

    $new_field_storage = FieldStorageConfig::create($new_field_storage);
    $new_field_storage->original = $new_field_storage;


  // Restore the data.
  foreach ($tables as $table) {
    $insert_query = $database
    foreach ($existing_data[$table] as $row) {

This is what I do. I would only use it to increase the length of a string. I have not tested, but assume that shortening a string will truncate data.

First, backup the database.

Then, edit the structure of the following tables (change yourfield to match the name of your field):


Change the length of the field_data_field_yourfield_value field (VARCHAR) in both tables to the value you want. This allows the fields to hold more characters. But doesn't tell Drupal about the change in length.

Next, locate this table:


Find your field in the list and edit the data value. Look for a section like this:


The length of the field in this example is 100. Change it to match the change you made earlier. If the number of characters changes (e.g. you increase it from 100 to 1000), change the s:3 value to reflect the new character count.

Flush all caches.

Edit the field on an entity type to which it is attached to verify that its length has changed.

Edit an entity with this field and verify that you are able to enter a value that is the new length.

That's all ....


Up-to-date method for Drupal 8 (for field name "field_myfield"):

  1. Backup database
  2. Edit structure for table node__field_myfield, set new length for column field_myfield_value.
  3. Edit structure for table node_revision__field_myfield, set new length for column field_myfield_value.
  4. Use Admin Toolbar Extra Tools module, top menu: go to Development > Config editor
  5. Filter by "field.storage.node.field_myfield"
  6. Edit the max_length: line under settings: to match new column length.
  7. Flush all caches.
  8. Enable the entity_update module.
  9. drush @miniloco upe --show
  10. Give up....

Will keep trying and will come and edit this if/when I find a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.