Is there any way to do this? For example, back a long time ago I created a field for phone number which was an integer. I quickly realized that making this field an integer was a mistake since it wouldn't accept characters other than numbers. Without having to create a new field is there a way that I can go back and change this field from being a number to text, or even better, to the phone.number field?

Comments

yched’s picture

Status: Active » Closed (won't fix)

Very unlikely - different field types have different options, there's no generic way to make a "translation".

You have to delete the "wrong" field and create a new one - or, if you don't want to lose the date, maybe you can try messing directly with the database...

jlevis’s picture

I have run to this same problem. I have a field for program code that I thought was all integers, but have just found out some of them have a letter as the first character. Unfortunately, I have already entered data for a few hundred nodes.

Does anyone know if this would be doable by doing an export then import of some sort?

yched’s picture

@jasonlevis : nope. A 'converter' module could come at some point, but not in any near future AFAIK.
Until then, you have to mess with the db directly - *please* make a db backup before doing anything !

- number fields and (unformatted) text fields have the same storage structure, so there should be no need to mess with the data tables (content_[field|type]_*)
- you need to change the field and field instance definitions in {content_node_field} and {content_node_field_instance} :

Assuming your field is named field_to_be_changed :
Best way to go is to create a dummy text field (field_dummy), and set it with the exact settings you'll want for your field_to_be_changed. If your original field_to_be_changed field is shared in several content types, share field_dummy all the same.
Then run the following queries :

DELETE FROM content_node_field WHERE field_name = 'field_to_be_changed';
DELETE FROM content_node_field_instance WHERE field_name = 'field_to_be_changed';
UPDATE content_node_field SET field_name = 'field_to_be_changed' WHERE field_name = 'field_dummy';
UPDATE content_node_field_instance SET field_name = 'field_to_be_changed' WHERE field_name = 'field_dummy';
TRUNCATE TABLE cache_content;

Untested and from the top of my head, but should work.

This will pretty badly break Views that use this field as a filter or argument, you'll need to edit and fix them by hand.