I have created a table by using hook_update_N() function. After creation, if i am trying to insert data into table but it is not storing. Is there any thing else is there to do after creating table by using hook_update_N()..?

  • Nope, creating it should do the trick. Please describe how you insert the data, and any error messages you see. – Free Radical Jun 19 '14 at 6:03
  • trying insert data by using node_save() function.. no error messages.. – Surender 32253 Jun 19 '14 at 6:38
  • Where have you placed the call to node_save()? – Free Radical Jun 19 '14 at 8:20

If you're using drupal_write_record, be aware of this warning in the documentation

Do not use drupal_write_record() within hook_update_N() functions, since the database schema cannot be relied upon when a user is running a series of updates. Instead, use db_insert() or db_update() to save the record.

You should be using db_insert or db_update instead.


You can not use node_save() inside the hook_update_N() function. You must first create the schema for your new table by running the update script. After having run the update script, use a DB manager such as phpMyAdmin to check that it has been created in the database.

Then, to use the schema, the node_save() function must to be called from your custom module, not from inside hook_update_N().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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