I am updating a module that I built for my site. When I originally built the module, I didn't know much about Drupal and I gave it a version of 0.0.1. Now I'm working on a completely different version that will be using 7.x-2.x as the version. I need to run an update for the module to work. I have this function

function contacts_blocks_update_7200() {
  // Update code.

When I go to update.php on my site, I get an error that there are no pending updates. I've also tried contacts_blocks_update_7201. Neither is working. I do not understand how to make an update run this function. I've had a similar issue with another module and was never able to get the update function to run and ended up doing it manually.

I checked the schema_version of the module in the system table and it says 0. I'd really like to learn how to do this. How do I determine the N for hook_update_N?

  • 7200 seems right to me. Can you make sure -- "Implementations of this hook should be placed in a mymodule.install file in the same directory as mymodule.module. Drupal core's updates are implemented using the system module as a name and stored in database/updates.inc."
    – arpitr
    Feb 15, 2015 at 15:34
  • The update function is in the file contacts_blocks.insall which is in the root folder of my module.
    – Robbert
    Feb 15, 2015 at 15:35

1 Answer 1


Provided your project's machine name is contacts_blocks, make sure that your implemenation of hook_update_N is located in a file named contacts_blocks.install that is inside your project directory. (Make sure you spell it exactly right contacts_blocks.insall will not work.)

The four digits should be [major version][minor version][2 digits for sequence], so the correct name in your case (branch 7.x-2.x) should be 72XX, where XX is some sequence number.

To figure out what number to use for the last two digits, run the following query:

SELECT schema_version FROM `system` WHERE name = 'contacts_blocks';

If it returns no result, then use 7200.
If it returns something below 7200, then use 7200.
If it returns a number above 7200, but below 7298, then increment with 1 and use that (e.g. if it returns 7202, use 7203).

If there is a weird value for schema_version in the systems table, and you're just experimenting (i.e. nobody else have your module, so you're not going to distribute the contacts_blocks.install file with your update to anyone), you can get a fresh start by disabling and uninstalling the module (just disabling is not enough), the reinstalling it again.

API link: function hook_update_N

  • Darn it. I hate those typos errors. The file name's extension was wrong. My comment above was a typo as well. The real file was missing the s instead of the t. Thank you for clarifying the process in general though.
    – Robbert
    Feb 15, 2015 at 19:10

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.