Drupal7: How to change an already existing text field to a text area

User login

Here is a useful snippet that you can use to change an already existing drupal textfield into a text area. Just replace the field_machine_name with the machine name of the field that you would like to change.

<?php
  db_query
("UPDATE {field_config} SET type = 'text_long' WHERE field_name = 'field_machine_name'");
 
db_change_field('field_data_field_machine_name', 'field_machine_name_value', 'field_machine_name_value', array(
   
'type' => 'varchar',
   
'length' => '20000',
  ));
 
db_change_field('field_revision_field_machine_name', 'field_machine_name_value', 'field_machine_name_value', array(
   
'type' => 'varchar',
   
'length' => '20000',
  ));
 
// Clear caches.
 
field_cache_clear(TRUE);
?>
Tags: 
Drupal 7, Drupal Quick Tips