Articles


How to update a mysql table field type in drupal 7.

How to update a mysql table field type in drupal 7.



Posted byJibin Jose,30th Apr 2016

For one of my Drupal sites we need to change one of the database field value from it to text as per the new requirement. This field type is a simple thing, we can use the Drupal hook_update_N for doing the same. The hook_update_N need to add inside the module. install file. This update option is possible for all the table fields. The below is the simple code to update the table field type.


/**
 * 
 * Implement hook_update_N 
 */
function mymodule_update_7100() {
  db_change_field('tablename', 'fieldname', 'fieldname', 
    array(
      'description' => 'Item description field',
      'type' => 'text',
      'size' => 'big',
    )
  );
}

Please run update.php to get the changes reflected inside the database.

Categories