Field Machine Name Change in Drupal 7

Screen Shot of code

I wrote my first GitHub Gist!

The code:

I know not that exciting really. I have been using another service ( for a while but it may be time to switch. Anyhow, on to the content. I was asked to provide an upgrade path from a 1.x to a 2.x version of a module. Unfortunately that included machine name changes to the fields of several content types. Ack. Even better was that these content types were stored as a feature module ( After doing some research and finding out what I was about to do was a very bad thing I set off and created a list of things that needed to happen in order for the upgrade path to work.

  1. All field database tables would need to be renamed. This includes both the field_data and field_revision tables.
  2. A few fields in each of the data and revision tables would need to be updated with the new name.
  3. The entries for each field in field_config would need to be changed
  4. The entires for each field in field_config_instance would need to be updated as well
  5. Revert the feature to tackle any other changes

One item that I didnt include was updating the mysql indexes on each of the field tables. I spoke to a DB guru and he didnt seem worried that the index name was not matching the fields in the index.

Long story short Drupal and field api do not want you to do this. So you will have to use some direct db alteration functions. Check out the gist. Its working fairly well.

I would like to put a big disclaimer out there to all people who are about to attempt this. This is a really really bad idea. This will work and not blow up your site completely if you do not have the fields you are renaming in other places like views or workbench. Do not change your field machine names unless you are absolutely sure that there is no other way or you are confident that you will not break anything.

Future plans include making this into a module. There is one out there for Drupal 6 (

Ill post again once that is up.

Happy Hacking.

Comments are closed.