Updating schema version with drush in Drupal 8

September 10, 2018

Submitted by twfahey on Mon, 09/10/2018 - 08:57

Occasionally when developing new updates for modules, the "schema version" has to be reset back if the local update code failed for some reason. In Drupal 7, this was a straightforward change to the `system` table, where each module was clearly listed with a `schema_version` column that could be changed via Pancakes relatively quickly. In Drupal 8, the approach is slightly different. You can find the value of each module schema in the `key_value` table, anything under the collection `system.schema`. Since the value is serialized, the cleanest solution to modifying a schema version is via drush, evaluating a core-bundled helper function meant for just this purpose:

drush ev "drupal_set_installed_schema_version('WHATEVER_MODULE', 8000)"

Of course, the "8000" value in this example can be whatever version you want to roll back to. That's it! Now you can reset the schema version quickly, and run the `drush updb -y` to re-run the updates and see if the code works as you need it.