2

I have a field list on my content type that I need to edit. Specifically I just need to change one of the key/value pairs. Unfortunately there's already content in the site so I can't just change it in the admin interface (it gives me an error that there are already records that use this).

I'm looking through my database (mysql) and I can't even find where the key/value pairings are stored. I can see the keys being attached to my nodes and can manually change them there, but that doesn't solve my underlying problem.

So my question is two-fold:

1) where is the table to edit field lists for a content type?

and

2) what's the preferred way to change a field list key/value pairing once content has been added to the site (too much to delete and start from scratch)?

Thanks!

2

In future use taxonomy for the list. That way you can add/edit to the list without any problems. Lists should be used for things that are constant, like the seasons of the year etc.

Use MySQL Workbench (assuming you are using MySQL). Open the table 'field_config' and do a select on it.

Look for your field in question. It's data is a blob. Right click on the blob and select 'Open Value in editor'. Select text.

You will see something like this:

a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:2:{s:14:"allowed_values";a:2:{i:1;s:3:"one";i:2;s:3:"two";}s:23:"allowed_values_function";s:0:"";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_list";a:1:{s:5:"value";s:16:"field_list_value";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_list";a:1:{s:5:"value";s:16:"field_list_value";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:1:{s:5:"value";a:1:{i:0;s:5:"value";}}s:2:"id";s:1:"6";}

You can see under allowed values I have two list entries:

1 => one

2 => two

To add 3 => three I change this bit:

"allowed_values";a:2:{i:1;s:3:"one";i:2;s:3:"two";}

To this:

"allowed_values";a:3:{i:1;s:3:"one";i:2;s:3:"two";i:3;s:5:"three";}

a:2 changed to a:3 as it is the count of values in the list

i:3 indicates the new key

s:5 is the string length of the word three

Then hit apply in the edit box, and hit apply in the SQL window and you are done.

enter image description here

So you don't want to add a new value, but edit an existing one. Use same process as above, but just edit the allowed_values, then run an SQL update on your two tables for the field : 'field_data_XXX', 'field_revision_XX' to update old key to new key.

  • @J Reynolds Brilliant. Thank you, it works like a charm. Also very interested to be learning a technique in Workbench finally. I'd downloaded it and played around with it, but not used it until now. I'd also wondered about that table field_config but figured I couldn't change the Blob. Anyway, thanks again! – Sage Apr 1 '15 at 18:34
  • For Drupal 8 it would appear this data is in the config table. I modified a key, value in the data blob, adjusted the string lengths but Drupal reported Attempt to create a field field_my_field that does not exist on entity type XX. I'm unsure of your statement to run SQL update to update the keys. When I look in the table field_my_field it doesn't seem to need this key? What did I not understand? thx. – sam452 Sep 8 '16 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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