Skip to content

Instantly share code, notes, and snippets.

@theodorosploumis
Created March 25, 2015 18:36
Show Gist options
  • Save theodorosploumis/6a08eb6e4e8c3ad5f3e8 to your computer and use it in GitHub Desktop.
Save theodorosploumis/6a08eb6e4e8c3ad5f3e8 to your computer and use it in GitHub Desktop.
Change drupal text field limit
<?php
$field_to_update = 'field_text_field_to_extend'; //Replace with field slug
$new_chars = '500'; //Replace with extended character limit
$result1 = db_query('ALTER TABLE {field_data_'.$field_to_update.'} CHANGE '.$field_to_update.'_value '.$field_to_update.'_value VARCHAR('.$new_chars.')');
$result2 = db_query('ALTER TABLE {field_revision_'.$field_to_update.'} CHANGE '.$field_to_update.'_value '.$field_to_update.'_value VARCHAR('.$new_chars.')');
$result3 = db_query('SELECT CAST(data AS CHAR(10000) CHARACTER SET utf8) data FROM {field_config} WHERE field_name = \''.$field_to_update.'\'');
foreach ($result3 as $result) {
$data = $result->data;
}
$data_array = unserialize($data);
$data_array['settings']['max_length'] = $new_chars;
$new_data = serialize($data_array);
$result4 = db_query('UPDATE {field_config} SET data = :data WHERE field_name = :field', array(':data' => $new_data, ':field' => $field_to_update));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment