2

In the middle of entering content I discovered the length of 15 characters of a particular field I set earlier is not enough.

In Drupal6 I could change the settings of a cck field. It could be potentially dangerous, but in my case it's a lossless transform, I just want to make a maximum size of a field a little longer.

But in Drupal7 I get the message saying it's impossible to change the field settings because there is some content stored in that field in database.

This restriction seems too strict to me. A warning message seems to be enough.

So my question is what's the reasons for this behavior and what can be done in my case? Manual deleting and recreating the content is not the option.

2 Answers 2

6

Unlike in Drupal 6 where setting the max length of a text field didn't have any influence on the database, but merely added a validation check, Drupal 7 will actual create a column that can only hold the selected number of chars.

You can get around this, but not though the UI, as you need to alter the table in the database.

What you need to do is alter the max length of the value column in the field tables named:

  • field_data_[FIELD NAME]
  • field_revision_[FIELD NAME]

The column you need to change should be called [FIELD_NAME]_value

Then you need to alter the configuration, which is serialized data in the data column in the field_config table for the field. You can either edit it directly if you are familiar with PHP serialized data or can do it with drupal_write_record. I believe the usual API function field_update_field wont work, as it should throw an exception not allowing the field to be saved, you can however use field_info_field to get the field data as it is stored in the database.

So in short, it can be done, but requires some custom hacking on the DB not using proper APIs.

An alternative solution would be to create a new field and migrate the data and then delete the old field.

2
  • Thanks for elaborate answer! I see it would be quite hard to tweak it and not to break anything. What's about an alternative? I mean, what's the easiest way to migrate the data of one content type from one field to another? Commented Jun 3, 2011 at 12:16
  • This approach has been explained in depth at drupal.stackexchange.com/questions/8829/…
    – Juampy NR
    Commented Sep 12, 2013 at 13:18
1

In most cases, especially during development or testing (when I don't need the data in the field already), I would just delete the field altogether and recreate it from scratch. If you need to keep data from the field, I'd consider doing the manual process outlined by googletorp.

The new way the Field API handles explicit-length text fields may be a pain, but it can greatly speed up requests in some cases, meaning I'm okay with the configuration tradeoff. Just always try to think ahead a digit or two ;-)

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.