14

I'm getting the following error on my Drupal 8 configuration page.

Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.

Content Update the node.rng_capacity field. Update the node.rng_registrants_duplicate field. Update the node.rng_registration_groups field. Update the node.rng_registration_type field. Update the node.rng_reply_to field. Update the node.rng_status field.

I'm not sure what caused these issues or how to go about resolving them. I think they may be leftover fragments/elements from when I deleted a registration or entity type.

5
  • 1
    The message shouldnt mean there isnt anything bad going on. Running drush entity-updates on your site should cancel these messages.
    – Daniel
    Apr 21, 2016 at 17:42
  • What else did you try? drush updb?
    – leymannx
    Jun 14, 2019 at 21:41
  • Hi, yes I tried both drush updb and drush entup. Entup would say success each time I ran it, but never seemed to update and it was there next time. Let me test the comments of the other answer - devel entity updates module. Thanks. Jun 16, 2019 at 15:39
  • You should never use drush entup for core updates. Always use drush updb. If this fails it would be a major core issue. In this case restore from a backup and wait for a fix which shouldn't take long because it would affect a lot of installations.
    – 4uk4
    Jun 16, 2019 at 19:44
  • Duly noted for the future thanks, Unfortunately I'd already ran Drush EntUp with the devel module installed but it seemed to sort the issue. Hopefully nothing that will later come back to bite me. Jun 17, 2019 at 21:01

7 Answers 7

13

You can solve this issue by two ways.

If you installed Drush, you can run drush entity-updates. Otherwise, add the following lines in the index.php file located in the Drupal root folder, before $response->send(); and reload the page.

try {
  \Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
catch (EntityStorageException $e) {
  print_r($e);
}

Then remove the code from the index.php file.

8
  • Can you post drush comment warning or error here? So I can figure out what is the problem exactly.
    – Rahul
    Dec 5, 2016 at 4:01
  • I deleted my comment, the problem was with the PHP version my drush was using ( I had two versions, shell was using the old one, so drush was too). Thanks!
    – Chayemor
    Dec 6, 2016 at 10:18
  • If anyone comes seeking this question how to change PHP version under which drush is running you can find this article helpful. <a href="fuelforbrain.com/… to change PHP version that drush runs under?</a>
    – Rahul
    Dec 7, 2016 at 7:25
  • I had this problem after updating from Drupal 8.3.2 to 8.3.3, but in my fields contained already data. <blockquote>The SQL storage cannot change the schema for an existing field</blockquote> Is there no simple way to update field storage and solve this mismatched entity error when there is already data in the fields?
    – drupalfan
    Jun 17, 2017 at 11:18
  • 3
    This solution does not work with Drupal 9.
    – Abe
    Dec 19, 2021 at 19:13
16

drush entity-updates (aka drush entup) has been deprecated as of Drupal 8.7.0. You either need to write an update script using hook_update_N(), or you can use the Devel Entity Updates module, which does the same thing as drush entup did previous to 8.7.0.

4
  • Many thanks Jaypan. First I've heard of this solution, but it worked perfectly. Installed the Devel Entity Updates Module you recommended and then ran drush entup again. This time it worked! I did vote up the answer, but because my rep is so low it's not display. Cheers Jun 16, 2019 at 16:01
  • Thanks a lot, Jaypan. Working perfectly. Your answer is always helpful. Feb 26, 2021 at 12:37
  • 2
    The "Devel Entity Updates" is not really suitable for a production release. Instructions for hook_update_N() can be found in drupal.org/node/3034742
    – donquixote
    Jan 3, 2022 at 11:57
  • 2
    the Devel Entity Updates module site says, "Do not use this to fix the Mismatched entity and/or field definitions error: again, this is not meant to fix production sites."
    – frazras
    Jul 17, 2022 at 4:07
12

Solved!

Go to the admin/reports/status and find the field machine name.

For Example: "paragraph.field_video_upload". Edit the field storage settings and save the configuration again. That's it.

It works.

enter image description here

4
  • It makes the error go away, but I'm still not sure if it actually worked properly.
    – colan
    Mar 30, 2022 at 19:15
  • @colan it does, exporting the config make it clear.
    – gagarine
    Apr 25, 2022 at 0:11
  • I was going crazy searching how to insert my lost storage schema configurations for two fields, I had gone down to SqlContentEntityStorageSchema and I was trying to understand how to invoke its protected methods... and it was SO simple :D I wish I could upvote this answer many times :) Jan 24 at 15:47
  • 1
    @colan, it depends on the underlying cause of the error. I have checked that the database, the field config and the field storage config are ok, and the only section that had been lost was the entity storage schema. It was missing for two fields (it can be checked looking at \Drupal::keyValue('entity.storage_schema.sql')->get('node.field_schema_data.field_my_custom_field')), and it was correctly restored after saving the field storage settings, so that was it – at least for me, YMMV. Jan 24 at 15:53
8

Find the field in /admin/reports/fields. For each entity that uses the field, edit the field and save the parameters again.

This should be updating the database and make the entity and the field match again.

2
  • 1
    This even works when the field in question is layout_builder__layout which is locked.
    – berliner
    Nov 24, 2021 at 23:16
  • 1
    +1. This and answer by @thirsty six works.
    – salah-1
    Mar 11, 2022 at 17:14
4

For Drupal 9, use devel_entity_updates module

composer require 'drupal/devel_entity_updates'
drush en devel_entity_updates
drush entity-updates

should fix the issue.

2
  • This fixed it for me. I had to run: [drush entup] after installation.
    – Abe
    Dec 19, 2021 at 19:11
  • While this may address the issue for some sites, it can't be used on production sites
    – Timmah
    Jan 10 at 0:29
3

It is clearly written in the Devel Entity Updates:

Do not use this to fix the Mismatched entity and/or field definitions error: again, this is not meant to fix production sites.

This will not help these issues.

Here some links that could fix the issues:

https://www.drupal.org/project/paragraphs/issues/3062300 https://www.drupal.org/project/commerce/issues/2656896

1
1

For Drupal 8 and Drupal 9, there is the Entity Update module, which allows to update an entity schema with Drush or without it.

The main objective of this module is to allow module developers and site administrators to update entity types schema even when entities have data.
The update can be executed via Drush (recommended), from the web browser, or programmatically.
The module also allows to view the list of entity types, the entity types update status, and show the content of an entity type.

1
  • I tried this and received the following In SqlContentEntityStorageSchema.php line 1849: The SQL storage cannot change the schema for an existing field (uri in file entity) with data.
    – Daniel
    Mar 8 at 13:41

Your Answer

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

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