Tuesday, 3 July 2012

How to add new column after installing Module in Drupal?

Using a hook_update_n() function we can able to add New Columns to the table.
Here, 'n' represents the number.

Suppose if we want to add a new column called 'newcol' to mytable1. First, we have to update our schema structure in modulename_schema() so that newly created tables get the new column. Then, add an update function to modulename.install:

<?php
function modulename_update_1() {
  $ret = array();
  db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int'));
  return $ret;
?>

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.