To add to @Eyal's root cause answer, I can offer a practical solution to solve the issue.
I had this issue when trying to import config when using
drush cim
My solution assumes the use of git for the Drupal source and that the config is in folder config/sync
relative to the root of the git source tree (and also, but not really relevant here, is that the site code is in web/
)
I got a similar error as the original poster/questioner.
With all my changes so far I wanted git add
ed and git commit
ted by me, I did a:
drush cex
to export the config out of the database. Now - this isn't the config I want to use of course. The config I want to use is in code and I want to import it into the database.
But what drush cex does in this situation is export as code the thing that the import error was "complaining" about being missing. So this means I can make this thing part of the config I'm going to import so that the error no longer occurs.
But of course, doing the drush cex
, other things will have been exported as well which I don't need or want and some of them would have overwritten / changed my config in code that I want to import. That's not a problem, because I can either:
- Delete this surplus config if it is a new file or
- revert to what was in git - the config I DO want - by git checkout of the changed file -
git checkout config-file
Then once I've removed and/or reverted config files and changes I don't need, I can rerun drush cim
- and - success. Hope this helps you.
Here's my example in action:
I tried to import - but it failed:
drush cim
The import failed due to the following reasons:
Unexpected error during import with operation delete for taxonomy.vocabulary.tags: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for node.type.page: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for node.type.article: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for contact.form.personal: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for contact.form.feedback: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for comment.type.comment: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for block_content.type.basic: Attempt to create a field body that does not exist on entity type node.
Unexpected error during import with operation delete for field.field.node.page.body: Attempt to create a field body that does not exist on entity type node.
So (with everything in git committed, including the config I want to evenrually import), I exported from the database:
ddev drush cex
[notice] Differences of the active config to the export directory:
+------------+--------------------------------------------+-----------+
| Collection | Config | Operation |
+------------+--------------------------------------------+-----------+
| | field.field.node.page.body | Create |
| | core.entity_form_display.node.page.default | Update |
| | search.settings | Update |
| | core.entity_view_display.node.page.teaser | Update |
| | core.entity_view_display.node.page.full | Update |
| | core.entity_view_display.node.page.default | Update |
+------------+--------------------------------------------+-----------+
So on doing a
git status
I got:
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .ddev/.gitignore
modified: .ddev/config.yaml
modified: composer.json
modified: composer.lock
modified: config/sync/core.entity_form_display.node.page.default.yml
modified: config/sync/core.entity_view_display.node.page.default.yml
modified: config/sync/core.entity_view_display.node.page.full.yml
modified: config/sync/core.entity_view_display.node.page.teaser.yml
modified: config/sync/search.settings.yml
modified: config/sync/system.site.yml
Untracked files:
(use "git add <file>..." to include in what will be committed)
config/sync/field.field.node.page.body.yml
So I could see that the missing field body file is in the newly created file, which is untracked. I don't need the modified files, so I can reset them to what is in git - the config I will want to import, by doing a git checkout on them:
git checkout config/sync/core.entity_form_display.node.page.default.yml
git checkout config/sync/core.entity_view_display.node.page.default.yml
git checkout config/sync/core.entity_view_display.node.page.full.yml
git checkout config/sync/core.entity_view_display.node.page.teaser.yml
git checkout config/sync/search.settings.yml
Then doing a
git status
just showed the new file (which is what I want to be part of my import to fix the missing body field issue):
Untracked files:
(use "git add <file>..." to include in what will be committed)
config/sync/field.field.node.page.body.yml
So I then did my import of my config:
ddev drush cim
+------------+--------------------------------------------+-----------+
| Collection | Config | Operation |
+------------+--------------------------------------------+-----------+
| | core.entity_form_display.node.page.default | Update |
| | search.settings | Update |
| | core.entity_view_display.node.page.teaser | Update |
| | core.entity_view_display.node.page.full | Update |
| | core.entity_view_display.node.page.default | Update |
+------------+--------------------------------------------+-----------+
Import the listed configuration changes? (yes/no) [yes]:
> yes
[notice] Synchronized configuration: update core.entity_form_display.node.page.default.
[notice] Synchronized configuration: update search.settings.
[notice] Synchronized configuration: update core.entity_view_display.node.page.teaser.
[notice] Synchronized configuration: update core.entity_view_display.node.page.full.
[notice] Synchronized configuration: update core.entity_view_display.node.page.default.
[notice] Finalizing configuration synchronization.
[success] The configuration was imported successfully.
With my config imported I can then go about removing the body field - because I didn't want it but needed to recreate it as described to get my configure import to go through.