Background: I have config read-only setup on non-development environments. So all configurations (including enabled modules) are created and exported from development site and imported to different environment.

Problem: I need few new content entity types to be imported and add content of those types in database update (i.e. hook_update_N()).

As per https://www.drupal.org/node/2762235, all database updates should run before configuration import. Since my entity definitions are in configuration, hook_update_N throws fatal that entity types do not exist. I can run config-import after hook_update_N, but it can cause other problems (as mentioned in above d.o issue).

How to import configuration and content in this case?

2 Answers 2


Don't add content using hook_update_N() there's not really anyway to make that work if the entity types are in config. What you can do is just use something like default content and add you own step to config import to look to see if any installed modules provide default content and create that.

  • Thanks @alexpott. TBH, my main use case is to move entities from one type to another(new) with set of field mappings.
    – vijaycs85
    Jan 6, 2017 at 0:28

One of the workaround is to run database update (hook_update_N) before and after configuration import. In hook_update_N check if your configuration changes are available. In my case, I just need to check if the new module is enabled:

function playground_deploy_update_8001() {
   if (!\Drupal::moduleHandler()->moduleExists('content_bar')) {
     throw new Exception('Update depends on Content Bar module which is not enabled.');
  // Content import/add code here.

This way, the first database update call throws error and proceed to config import. second database update imports the content properly.

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.