Drupal - How do I change the machine name of a field once it's been created
My procedure is to use drush to clone the field first, then copy the field data with DB queries into the new field table. After I verify the contents of the cloned field, I delete the original field.
I do it this ways because I think the drush method of cloning fields will always be at least as reliable as any cloning code I might craft myself, the data copy query is pretty simple, and I get to check the new field before deleting the original.
drush field-clone field_my_field field_my_field_clone
- Insert rows into
field_my_field_clone
, e.g.,INSERT field_my_field_clone SELECT * FROM field_my_field;
- Verify the contents of
field_my_field_clone
. - Delete the field using the UI, e.g.,
admin/structure/types/manage/my-content-type/fields
In short, you can't change the machine name. In theory, it's obviously possible, but it will require quite a bit of messing with the database. If you've only just created the field, it's far easier to remove it and create a new one.
The basics would be to rename all entries on field_config
and field_config_instance
, but as soon as you start using the field, the machine names get's stored in a hundred different places. Views config, Panels config, Features and more, and by then, changing it is not fun.
Deleting fields can be done on: admin/structure/types/manage/[machine_name_of_content_type]/fields
, which you can reach through the "Manage fields" tab on any content type.
In Drupal 7, you can use the Field Rename module. In Drupal 6, you can use CCK field rename module.