I'm working on a module, and I changed a couple field types in the schema. I didn't take a backup before testing it and messed up the DB (it's just a dev site). Anyway, I reinstalled everything, and the schema version is set to that of the highest update. However, I actually do need to run the update; a View I have wouldn't install if I had the updated schema in the module code, so I figured this would be a good way to test that update.

How do I reset the schema version of my module to a particular version? In Drupal 7, I would have done this:

drush sqlq "UPDATE system SET schema_version=8102 WHERE name='flllpdf' AND type='module'"


While accessing state directly works, you can also just use the API: drupal_set_installed_schema_version(). Which actually exists unchanged at least since 4.7, as visible on the linked documentation page. Probably one of the few API functions that existed for so long ;)

To set it from drush:

drush ev "drupal_set_installed_schema_version('fillpdf', 8012)"

Note: In Drupal 7 you need to add extra include 'includes/install.inc';.

  • 6
    Also nice if you simply need to check quick: drush ev "echo drupal_get_installed_schema_version('MODULE')"; api.drupal.org/api/drupal/core%21includes%21schema.inc/function/… – ben.hamelin Oct 23 '17 at 20:20
  • or drush pm-info modulename – Beanluc Sep 11 '18 at 15:56
  • @Beanluc - using drush pm-info modulename will give you the version of the module, but not the schema update version. – siliconmeadow Apr 8 '20 at 10:15
  • Where do you need to add this: 'Note: In Drupal 7 you need to add extra include 'includes/install.inc';.' in the command or in the .module? – Michiel Dec 1 '20 at 15:08

Drupal 8 now uses the keyvalue service to store information about the schema version. This is the same API the State API itself uses.

Value information is serialized when stored in the database, so using a direct SQL query is sub-optimal. Instead, use drush php-eval (or a script that bootstraps Drupal, if you don't have Drush) to execute the following:

  \Drupal::keyValue('system.schema')->set('fillpdf', (int) 8102);

Change fillpdf and 8102 to your module name and desired schema version, respectively.

The Drush form of this command is:

drush ev "\Drupal::keyValue('system.schema')->set('fillpdf', (int) 8102)";

  • Note that if you're using ddev then this throws a bash error. You'll need to ddev ssh into the vm and then the command runs fine. – Mrweiner Feb 19 at 20:16
  • It's possible to run it from bash, but the escaping is a bit of a pain, so ddev ssh is indeed easier. – wizonesolutions Mar 10 at 9:45

To SET and GET module updates via code (without Drush). Below is the code

GET  = drupal_get_installed_schema_version('moduleName');

SET = drupal_set_installed_schema_version("moduleName", "8000");

Can also go update it directly in the database. If you're using something like Sequel Pro (mac) or whatever database UI tool windows/linux has it's really easy. Arguably not the best idea, and would not advise doing this against a production level database, but it'll get the job done!

Table = key_value

collection = system.schema
name = fillpdf (your_module)
value = update to i:8102;

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.