I'm trying to convert a long-text field into a text-field. The only thing I found so far is the "field_config" table in the database. But any change there is only leading to errors. Do I have to change it somewhere else?
-
1text fields by default have limited size, meaning if the long text exceeds that, you will run into some problems. The best way is probably to add a text field to the content type with the settings you want, and then use a one-off function to copy the data (trimming as necessary to fit in the new text field) directly in the database.– GeoffJul 31, 2014 at 16:05
3 Answers
Once a field is created from admin then it can not be edited later. Because field data is saved in Binary form and can not be edited.
e.g if we have field 'test' then it will have table 'field_data_field_test' and 'field_revision_field_test' in the database. Now change its datatype directly in the database.
Export these tables as a sql file and delete the old field in the manage field section of content type using admin.
Create the new field with the same name as it was before and choose the appropriate datatype
- Now delete the newly created table 'field_data_field_test' and 'field_revision_field_test' and import the file that were exported earlier.
Other way you can create a new field and copy the data from old tables to new table and change settings later.
Hope it will help you!
Thanks to Geoff. As my long-text never was bigger than the textfield size (255) I could use this solution with ease. I did it the following:
Created a new field "textfield"
Did a database action:
INSERT INTO newtable (newfields)
SELECT oldfields FROM oldtable
and then deleted the old field.
I posted a php script that converts from text field to long_text field. You could easily reverse it: