As we know : it's impossible to unsintall a module whithout being forced to remove all the data that's belongs to it. The problem is, if we want to update a module we are obliged to uninstall it and then reinstall to get the changes work.

At developpement phase, it's ok , but what about being in a production site and having a big amount of data we don't want to loose, by just adding a field , or changing a type ....

Is there any best practises? Is there a process that could be advised? Is there any feedbacks of your own experience?

For example, I would guess : export data and then import data after the reinstall?

Thank you so much!

  • 1
    Why are you obliged to uninstall a module to update it?
    – ya.teck
    Nov 24, 2016 at 12:49
  • There is no case that you have to uninstall a module before update.... unless there is no upgrade path for the contrib module.
    – Jimmy Ko
    Nov 25, 2016 at 11:17

2 Answers 2


You can update your database with


if your module define hook_shema


  • I had no idea of what are hooks :D , well I'll try, could give a links for drupal 8 tutorials. (I find tutorial for drupal 7 not 8 )
    – Asy
    Dec 14, 2016 at 16:19

In order to make my changes take effect without removing all data -> uninstall -> reinstall the module .

Here the steps :

  1. Make the changes (in my code , for exemple add a field in my entity class)
  2. Add a hook_update_N() in yourmodule.install (yourmodule is your module name) yourmodule.install is in the root od your module, if not exist create it
  3. Here the content of yourmodule.install

    <?php /** * Document your changes */ function yourmodule_update_8001() { \Drupal::entityDefinitionUpdateManager()->applyUpdates(); }

  4. Execute update.php et the change take effect in the database !

NB: I made my changes in my custom module code using BaseFieldDefinition, ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.