Hi guys,

I've been tasked to update the maxlength on some fields within an existing Drupal install.

Within the CMS I navigated to the field settings page and can see the maxlength value set at 30
(/admin/structure/field-collections/field-offers/fields/field_title/field-settings)

I need to increase this value, but the field is disabled and accompanied by the following message:
"There is data for this field in the database. The field settings can no longer be changed."

After some research I've found that this can be the case with Drupal 7, but are any workarounds known of? I'm loathe to modify the DB direct as I'm working on a high-traffic site with no option of downtime!

Thanks in advance,
Graham

Comments

hughworm’s picture

I've had to do this kind of thing a few times. I find it works well if I back up the field data in SQL, and empty the field tables, then I can make the changes without Drupal complaining.
Here's a sample script that works on a field called "field_foo" in 4 sections to run a different stages:

  1. Backup
  2. Do changes in Drupal
  3. Restore
  4. Drop backup:
1a) create backup tables;
CREATE TABLE field_data_field_foo_bak AS SELECT * FROM field_data_field_foo;
CREATE TABLE field_revision_field_foo_bak AS SELECT * FROM field_revision_field_foo;
  
1b) empty real tables and clear cache;
TRUNCATE field_data_field_foo;
TRUNCATE field_revision_field_foo;
TRUNCATE cache_field;
2) NOW STOP AND CHANGE THE FIELD SETTING, THEN...;
3) Copy data back;
INSERT INTO field_data_field_foo SELECT * FROM field_data_field_foo_bak;
INSERT INTO field_revision_field_foo SELECT * FROM field_revision_field_foo_bak;
TRUNCATE cache_field;
4) WHEN YOU'RE HAPPY, DROP THE BACKUP TABLES;
DROP field_data_field_foo_bak;
DROP field_revision_field_foo_bak;

Works like a charm and it's quick.
Obviously try in test environment first and do the real thing in Maintenance mode!

If at first you don’t succeed, call it version 1.0.