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.

<?php
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

<?php
$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

drupal_get_schema() uses

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

<?php
$schema
= drupal_get_schema('mytable', TRUE);
print_r($schema);
?>

It will take a bit longer though.

Thx Drave, I know the reason

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