17th November 2016 - 5 minutes read time
I had to update a Drupal 7 site recently and needed to change the field keys of a list field to be different values. This wasn't possible from within Drupal as it does a pre-check to make sure that the key doesn't already exist. If it finds any values present in the database with that key then it will reject the change. This is absolutely correct but causes a little bit of an issue when you need to update these values.
The solution to this is to alter both the field definition and the field data via directly altering them in the database. The following function provides a neat little way of doing this to a field by just passing in the field name and what the key values need to change to.