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

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

Recent Comments

Forward by Dries Buytaert, Founder and Project Lead, Drupal; CTO Acquia.

Order now from:

Managing Expectations Podcast with DrupalEasy

Author Interview http://tinyurl.com/8a8nxno

We provide the most Shiny Drupal Bits & Pixels

Since Drupal 4.x