Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
6.x-2.6
Component:
General
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Nov 2009 at 07:13 UTC
Updated:
30 Mar 2011 at 14:23 UTC
I have a CCK field that was originaly defined as "integer". Now I realized the field should be "decimal". Is there a way to convert an integer field into decimal?
Any help is greatly appreciated!
Thanks!
Comments
Comment #1
markus_petrux commentedCCK 6.x-2.1? If that's true, please upgrade! ;-)
Back to the question... well, there's no magic in CCK to convert one field to another. You should do it yourself. And here, there are probably many ways to do it. The basic steps would be:
1) Make backups and be sure that you can use it to recover. I would even suggest trying on a development environment first, and only proceed in production when you're 100% sure the procedure works.
2) While still keeping the old field, go to "Manage fields" screen and add the new one.
3) Use custom query to copy the values from field A to field B doing the proper conversion.
4) Remove all the records from the content cache table.
5) Check the nodes to see if the new field has the correct values.
6) Finally, you can now visit the "Manage fields" screen to remove the old field.
In regards to step 3) ... if the fields are not shared between several content types and do not accept multiple values, they are located in the per content type table. Otherwise, they are located in their own per field table, and so that step is a bit more complex, but still possible.
Comment #2
markus_petrux commentedComment #4
tinem commentedI needed to change a cck field from text to integer and tried this in phpmyadmin (it's only a testsite and my first drupalsite)
UPDATE 'content_type_copenhagen' SET 'field_postnummer_value'='field_postnummer2_value';but the data was NOT copied and in both field there now is only NULL - have I done something wrong, please?
Comment #5
lmartin commentedAssuming that 'field_postnummer2_value' is your new field and 'field_postnummer_value' is your old one, you've actually set the old field value to the new one, which is probably why they are both now NULL. So, just reverse the two fields in the SET clause.
Comment #6
tinem commentedWhat a stupid mistake. But I'm a person not programming in php mysql. :-)
It's functioning. But now I also need to change my Views before I delete the first field_postnummer_value, right? And should I change it some other places too?
Comment #7
tinem commentedNow everything is functioning as it should converting a textfield to integer - thanks a million for your post. :-)
Comment #8
nikhil.goyal commentedI could not get this query to work..
UPDATE 'content_type_copenhagen' SET 'field_postnummer2_value'='field_postnummer_value';
Mysql throws a error..
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''content_type_copenhagen' SET 'field_postnumber2_value'='field_postnumber' at line 1
Could anyone point the error.
Comment #9
drupalnesia commentedUPDATE `content_type_copenhagen` SET `field_postnummer2_value`='field_postnummer_value';
or
UPDATE content_type_copenhagen SET field_postnummer2_value = 'field_postnummer_value';
You must use ` instead ' for "content_type_copenhagen" and "field_postnummer2_value"
Comment #10
Sinan Erdem commentedUPDATE content_type_copenhagen SET field_postnummer2_value = 'field_postnummer_value';this code doesn't work for me but this does (without the ' s around field_postnummer_value):
UPDATE content_type_copenhagen SET field_postnummer2_value = field_postnummer_value;Comment #11
tinem commentedI'm surprised about #9 and #10 and think it is spammers right or?
content_type_copenhagen is made especially in my project and don't understand what these people use it for so are sure it's spam. :-(
Comment #12
Sinan Erdem commentedHaha.. tinem, it is just an example taken from your case. Of course I don't use the exactly same field names. I just didnt want to give my field names not to confuse other people who can come and see this page in the future.