Hi all,

I am working on my own module and i want to add a column to the existing schema. so i make use of the hook_update_n and add it as follow.

function mymodule_update_7000() {
  $spec = array(
    'type' => 'varchar',
    'description' => t('some description.'),
    'length' => '255',
    'not null' => FALSE,
  ); 
  db_add_field('mytable', 'new_col', $spec);
}

After that, i run the update.php and the new column is added without any problem.

But when i try to update a record using drupal_write_record(), the newly added field cannot be updated.

I try to get the schema of the table by

$schema = drupal_get_schema('mytable');
print_r($schema);

i found that the $schema does not contains the newly added field. Did i missed anything?

Thanks and any help is appreciated.

Kit

Comments

Drave Robber’s picture

drupal_get_schema() uses static caching, so you may want to tell it to rebuild the data:

$schema = drupal_get_schema('mytable', TRUE);
print_r($schema);

It will take a bit longer though.

ykyuen’s picture

Thx Drave,

I know the reason for my problem. That is becoz i didn't add the new column in hook_schema().
Thanks for your help.

Regards,
Kit