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'"

| improve this question | | | | |

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';.

| improve this answer | | | | |

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)";

| improve this answer | | | | |

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");
| improve this answer | | | | |

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;

| improve this answer | | | | |

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.