-1

Can anyone please help me to write the update db hook for altering the table. Actually I want change the column size of desc field something like :

function abc_update_1001(){ // what will the code }

Example : Table name : shared_data

--------------+---------------+------+-----+---------+-------+
| Field        | Type          | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| id           | varchar(50)   | NO   | PRI | NULL    |       |
| title        | varchar(29)   | NO   |     |         |       |
| desc         | varchar(2000) | NO   |     |         |       |
| time         | datetime      | NO   |     | NULL    |       |
+--------------+---------------+------+-----+---------+-------+

The alerted table should look like:

--------------+---------------+------+-----+---------+-------+
| Field        | Type          | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| id           | varchar(50)   | NO   | PRI | NULL    |       |
| title        | varchar(29)   | NO   |     |         |       |
| desc         | varchar(3000) | NO   |     |         |       |
| time         | datetime      | NO   |     | NULL    |       |
+--------------+---------------+------+-----+---------+-------+

Many Thanks

2
  • Drupal 7 or 8??
    – Jaypan
    Commented May 18, 2017 at 9:06
  • Hi Jaypan , i use Drupal 7.
    – shrikant
    Commented May 18, 2017 at 10:04

1 Answer 1

3
function hook_update_n() {
  db_change_field('shared_data', 'desc', 'desc', array(
    'type' => 'varchar',
    'length' => 3000,
  ));
}
1
  • Add this code to module.install in your module
    – Udit Rawat
    Commented May 18, 2017 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.