Drupal - How do I rename a field?

I've had the misfortune to need to do this before :P , and my advice would be as follows:

Forget about renaming the existing field; the machine name is scattered across several different hard-to-edit places, and you'll probably miss some and get weird errors. For example, if you just rename the tables and the configuration, the field API will throw a fit when it tries to delete the old tables and finds they're already gone. The schema information is kept in the keyvalue store, and cannot be rebuilt from scratch, so if you make manual changes it's easy to end up in a broken state.

Instead, recreate the field with the correct machine name, then copy over the data with SQL, and finally delete the old field.

INSERT INTO node__field_new SELECT * FROM node__field_old;
INSERT INTO node_revision__field_new SELECT * FROM node_revision__field_old;

Tags:

Entities

8