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

10 Answers 10

11

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
  • 1
    applyUpdtes() does not exist anymore. Error: Call to undefined method Drupal\Core\Entity\EntityDefinitionUpdateManager::applyUpdates() in main() (line 24 of index.php). How can this be solved in Drupal 9?
    – drupalfan
    May 13, 2021 at 18:14
  • 6
    This solution does not work with Drupal 9.
    – Abe
    Dec 19, 2021 at 19:13
25

Solved!

Method 1: 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

(or)

Method 2: If it's not working, please try the method below.

.install

<?php

/**
 * Implements hook_update_N().
 */
function HOOK_update_9001() {

  $entity_type_manager = \Drupal::entityTypeManager();
  $entity_type_manager->clearCachedDefinitions();

  $entity_type_ids = [];
  $change_summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary();
  foreach ($change_summary as $entity_type_id => $change_list) {
    $entity_type = $entity_type_manager->getDefinition($entity_type_id);
    \Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
    $entity_type_ids[] = $entity_type_id;
  }

  return t("Installed/Updated the entity type(s): @entity_type_ids", [
    '@entity_type_ids' => implode(', ', $entity_type_ids),
  ]);
}

RUN drush cim & drush cr

7
  • 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, 2023 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, 2023 at 15:53
  • 1
    @ThirstySix Since mine involved the Webform module, I found it provides a Drush command that will fix it: drush webform:repair. This should be followed by a config export.
    – mbomb007
    Apr 5 at 14:57
18

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.

6
  • 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
  • Another thing in Drupal that used to be a simple one-liner that now requires coding knowledge...
    – Timmah
    Jun 22, 2023 at 4:13
11

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

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, 2023 at 0:29
4

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, 2023 at 13:41
0

For Drupal 10 or Migrated from Drupal 9 to Drupal 10, or migrated Contrib modules like Paragraph

You need to add devel_entity_updates

$ drush composer require 'drupal/devel_entity_updates:^4.1'

Then Enable

And Run the Drush command

$ drush devel_entity_updates

The following updates are pending:

paragraph entity type : 
The paragraph.field_reusable_paragraph field needs to be updated.

 Do you wish to run all pending updates? (yes/no) [yes]:
 > yes

 [success] Finished performing updates.

This resolved the above issue

1
  • Warning: The devel_entity_updates module clearly states: "Do not use this to fix the Mismatched entity and/or field definitions error: again, this is not meant to fix production sites."
    – jofitz
    Jan 16 at 12:15
0

You can Add hook_update_N() hook (in module_name.install file): to fix Mismatched entity and/or field definitions error for Configuration

/**
 * Update the Paragraph field definitions for mismatched fields.
 */
function hook_update_N() {
  try {

    $entityTypeManager = \Drupal::entityTypeManager();

    // Get the media entity type.
    $paragraphEntityType = $entityTypeManager->getDefinition('paragraph');

    // Install the media entity type to ensure field updates.
    \Drupal::entityDefinitionUpdateManager()->installEntityType($paragraphEntityType);

  }
  catch (\Exception $e) {
    watchdog_exception('logger_name', $e, 'hook_update_N failed');
  }
}

Note: I used nkf_update_8901() for hook_update_N(), where module_name : nkf, N denotes 8901

Follow this document to read more about hook_update_N() hook

I have used this approach to fix a "Mismatched entity and/or field definitions" error for Configuration due to couple of reasons:

In some projects :

  • Lower(dev) env can use "devel entity updates" but on higher(stg/prod) it is not recommended to use "devel entity updates" module. so in this particular scenario this approach hook_update_N() can be used

  • It also helps to keep track of recent changes related to particular entity updates of db at code level

0

You can use the below code(on module_name.install file) to fix this mismatched entity issue. I tried this on Drupal 10 version. Please post your comment if you need any clarification on this.

/**
 *
 * Mismatched entity and/or field definitions Fix.
 */
function hook_update_N() {

  $entity_type_manager = \Drupal::entityTypeManager();
  $entity_type_manager->clearCachedDefinitions();
  $entity_type_ids = [];
  $change_summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary();
  foreach ($change_summary as $entity_type_id => $change_list) {
    $entity_type = $entity_type_manager->getDefinition($entity_type_id);
    \Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
    $entity_type_ids[] = $entity_type_id;
  }
  drupal_flush_all_caches();
  return t("Installed/Updated the entity type(s): @entity_type_ids", [
    '@entity_type_ids' => implode(', ', $entity_type_ids),
  ]);
}

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.