Tuesday, May 11, 2010

how to change a CCK field name

CCK does not provide any UI to do that, since it's not supposed to be a feature.
if you really need to, the steps to do that manually in the db are :

Say you want to rename field_old_name to field_new_name

0- backup you db :-)

1- edit the relevant value in {content_node_field}.field_name - there should be one line

2- edit the relevant values in {content_node_field_instance}.field_name and {content_group_fields}.field_name (if you have enabled fieldgroup.module) - there could be several lines to alter

If the field is multiple or shared between several content types
3a- data table is {content_field_old_name}. rename it to {content_field_new_name}

If the field is single or not shared
3b- data table is {content_type_(the_content_type)}; Don't rename

4- Rename the content_field_old_name table to content_field_new_name

5- Rename the content_field_new_name.field_old_name_value column to content_field_new_name.field_new_name_value

6- empty tables {cache}, {cache_content} and {cache_views} (if using Views 1.6+)

7- Make sure you do "Rebuild Menu"

8- empty tables again {cache}, {cache_content} and {cache_views} (if using Views 1.6+)

9- Visit your site and check the results :-) - you'll probably need to resave your the views that refer to the field

Note: you might want to review:
"php code" of "default value" of a content type
"php code" of "allow value" of a content type.

No comments: