6

I am getting the following error:

Drupal\Core\Field\FieldException: Attempt to create a field body that does not exist on entity type node. in Drupal\field\Entity\FieldConfig->getFieldStorageDefinition() (line 286 of core/modules/field/src/Entity/FieldConfig.php).

Context is that I recently switched from one branch to another and did some config imports.

My guess is that this is related to a field.storage issue? What precisely would be causing this error? I'd provide more information about my content types, but I really don't know at this point where it can be narrowed down to.

I'm not finding any real sources on this particular error.

9

You attempted to create a field using configuration without creating the field storage configuration.

In the field configuration YAML you can see a field_storage property. That is the id of the field storage configuration that needs to also be imported.

| improve this answer | |
  • 1
    What particular piece of YAML would it be in? I searched the entire directory (especially the field.field.node.article.body, etc, etc) for field_storage and was unable to find anything – Jack Ryan Jan 24 '17 at 21:50
  • 2
    I think you are missing the field.storage.node.body configuration. You can copy the base configuration from the node module (core/modules/node/config/install/field.storage.node.body.yml) – Eyal Jan 24 '17 at 21:54
  • No, I've absolutely got it, in both YML and I put it into my database before posting here. – Jack Ryan Jan 24 '17 at 21:59
  • a:17:{s:4:"uuid";s:36:"230952c6-9c0c-4a0f-b8ac-dba902e8e8e8";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"module";a:2:{i:0;s:4:"node";i:1;s:4:"text";}}s:5:"_core";a:1:{s:19:"default_config_hash";s:43:"EBUo7qOWqaiZaQ_RC9sLY5IoDKphS34v77VIHSACmVY";}s:2:"id";s:9:"node.body";s:10:"field_name";s:4:"body";s:11:"entity_type";s:4:"node";s:4:"type";s:17:"text_with_summary";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"locked";b:0;s:11:"cardinality";i:1;s:12:"translatable";b:1;s:7:"indexes";a:0:{}s:22:"persist_with_no_fields";b:1;s:14:"custom – Jack Ryan Jan 24 '17 at 22:00
  • 1
    Oh, it worked, I just had to completely kill my VM and restart it to make it recognize it correctly. – Jack Ryan Jan 24 '17 at 22:03
0

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 added and git committed 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.

| improve this answer | |

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