Drupal - How to get hook_install() to run all hook_update_N()?

You shouldn't get your install hook to run updates. When a module is installed for the first time no updates should be necessary.

Updates are used when the module already is installed (the database or variables have been created). In that case, you don't want to reinstall the module as it will wipe all data, instead you create update_N hooks. Drupal will detect which updates are needed and those will be run going to update.php. In Drupal 6 it will auto select which updates to do, but you can change it, while this is not possible in Drupal 7.

Drupal detects which updates are needed by saving the number of the last run update. This can be changes in the database, which will allow to rerun updates in Drupal 7. Rerunning updates is usually a bad idea and will most often cause errors and can in some cases mess up your data.

Always remember to backup your database before running updates.


The purpose of the hooks is different.

  • hook_install() is invoked when a module is installed; it means the module was not previously installed, and therefore, it doesn't need to be updated.
  • hook_update_N() is invoked when a module is already installed, and it needs to be updated.

If there are some tasks that needs to be done both when the module is installed, and when the module is updated, then the code should be present in both the hooks. There are no module that invokes all the update hooks during the installation, and that would be especially wrong when the update functions update the schema of the database tables used from the module; hook_schema() should always return the updated schema, and updating the schema also with the update functions would be wrong.

The code you wrote doesn't work because calling one of the update functions doesn't automatically execute all the other update functions.
Calling the update functions from the implementation of hook_install()is wrong, as it wrong to call an update function from another one; if there is some code that needs to be executed from two or more update functions, then that code should be placed in a function that is called from the update functions, and from hook_install(), if necessary.


The install hook is only called when the module is freshly installed, so there is no need for any updates. The updates are executed only when the module is already installed, so it can apply additional changes.

To force the update functions to run on install, you've to change your schema version, for instance:

function mymod_install() {
  // Reset the schema version, so our update hooks can be processed during the installation.
  drupal_set_installed_schema_version('mymod', '7000');
  // Then run the updates as usual.
  mymod_update_7001();
}

Or run it from drush: drush -y updb.

See also: Is it possible to force your module's update hook to run?