I have a field that is type text and I want to convert it to type List (text) in Drupal 7. I can’t simply change the value, as it won’t let me, is there an easy way to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no easy way, no. As far as I can tell these are the manual DB changes you’ll need to make:
In
field_configchange thetypecolumn to ‘list_text’ andmodulecolumn to ‘list’ for your field.Then you’ll need to change the serialised array in the
datacolumn to match that of a list type (it’ll have the settings for text types at the moment obviously). There’s no easy way to show you how to do it here, the best way would be to compare the serialised array with one for a different field of a list type, then you’ll be able to see what values you need to remove/change. Theallowed_valuesarray undersettingswill be where you put your list’s values. Once that’s changed, re-serialise it and put it back in thedatacolumn for your field.After that remove any columns from your field’s
field_dataandfield_revisiontables that begin withfield_myfield_but aren’tfield_myfield_value(the list type still needs that column).Add an index to those tables for the
valuecolumn.Clear your caches
I must warn that’s completely untested it just seems to make sense looking at the table structures, it’d be a good idea to take a back up of the three tables you’ll be playing with just in case.