Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'd like to change the keys for a list (text) field type that already has content. Through the admin interface Drupal will tell you that "There is data for this field in the database. The field settings can no longer be changed." Is there any way to do this safely? Here's what I'm considering:

  1. db_change_field
  2. Direct SQL manipulation
  3. Changing values of content

I haven't messed with db_change_field before and am not even sure about it.

share|improve this question

1 Answer

db_change_field() is for changing the schema of a single column in a table, it doesn't relate to the field system as such.

The only way to change the name of a field is through direct (or pseudo-direct, using db API functions) manipulation of the database. These are things that need to change:

  • Name of the field in field_config
  • Name of corresponding field in field_config_instance
  • Name of the field_data_FIELD_NAME and field_revision_FIELD_NAME tables
  • Names of the data columns in the data and revision tables (probably FIELD_NAME_value and FIELD_NAME_format in your case)

After that clear the cache (preferably manually, i.e. truncate all tables that match the name cache_*) and you should see the changes in the site.

That should work on a stock install, but your mileage will likely vary if you have any contrib modules installed that provide functionality based on a field's name. I can't think of any except Field Collection of the top of my head, which won't apply to a text field, but there are probably others.

Whatever you do, take a backup of the database before you start playing around with it!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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