I sometimes run into the issue, when my PHP code has errors. I run update.php, but it fails with a php error message. After that, Drupal seems to think that the database is up-to-date, but it isn't. Trouble is, running update.php again does not solve the problem.

For example, just now, it has failed to create the tables for a newly created entity. update.php does nothing, but all my Entity code – of course – fails with database errors.

I don't know how to recover from this situation, other than uninstalling and reinstalling the module, which means killing all content first.

  • 2
    Restore the database from the backup you've made before running update.php and then fix the module code. If it's not your own module look in the issue queue. – 4k4 Mar 29 '18 at 16:45
  • Backup?? Er ... :-D – Hendrik Mar 29 '18 at 17:21
  • OK, I didn't have a backup, so what I did was: 1) bugfixes, 2) export all configuration, 3) uninstall and reinstall module, 4) import configuration. I didn't mind the content, but needed to keep configuration (fields etc.). – Hendrik Mar 30 '18 at 10:34

You could also rerun the update after you fixed your code.

See here: reseting the hook_update_n status of a module

  • Yes, if you've located the error and know that it stopped the update hook early, before it could make changes to the entity tables, then you can re-run it on the same database. Otherwise you don't know if the database is corrupted and it is advisable to restore the database first. – 4k4 Apr 4 '18 at 11:47

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.