4

I'm developing a site in Drupal 8 in Acquia Dev Desktop 2 on Windows 10. After updating to 8.5.0-beta1 I noticed this error on my status page (although it may have been there earlier in 8.4.4):

ENTITY/FIELD DEFINITIONS
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Custom menu link
The menu_link_content.field_most_common_name field needs to be updated.

Mismatched entity and/or field definitions

It's possible this error came from the Menu Item Extras module, which I had installed a couple of months ago, but since deleted.

Following popular advice, I ran drush entity-updates. That did not cure the problem. The output (typed manually) from my CMD window is below:

menu_link_content entity type :
  The menu_link_content.field_most_common_name field needs to be updated.
Do you wish to run all pending updates? (y/n): y
Drupal\Core\Entity\EntityStorageException: Exception thrown while
performing a schema update. SQLSTATE[42522]: column not found: 1054 unknown
column   [error]
'field_most_common_name_argument' in 'where clause': SELECT 1 AS expression
FROM
{menu_link_content__field_most_common_name} t
WHERE (field_most_common_name_target_id IS NOT NULL) OR
(field_most_common_name_display_id IS NOT NULL) OR
(field_most_common_name_argument IS NOT NULL) OR
(field_most_common_name_title IS NOT NULL) OR
(field_most_common_name_data IS NOT NULL)
LIMIT 1 OFFSET 0; Array
(
)
 in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException()
(line 1535 of C:\Users\Nick\Sites\devdesktop\drupal\core\lib\Drupal
\Core\Entity\Sql\SqlContentEntityStorage.php).
Failed: Drupal\core\EntityStorageException: !message in
Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException()
(line 1535 of
C:\Users\Nick\Sites\devdesktop\drupal\core\lib\Drupal\Core\Entity
\Sql\SqlContentEntityStorage.php).   [error]
Cache rebuild complete.   [ok]
Finished performing updates.   [ok]

Based on the 2nd answer here and this reference, I have made a custom module called "Database Fix" with the following content in the database_fix.module file. I am not a coder, so there is plenty of guesswork involved here:

<?php

/**
 * Fix database by updating menu_link_content.field_most_common_name field
 *
 */
function database_fix_update_8501() {
    $manager = \Drupal::entityDefinitionUpdateManager();
    if ($field = $manager->getFieldStorageDefinition('field_most_common_name', 'menu_link_content')) {
      $manager->updateFieldStorageDefinition($field);
    }
}

I enabled the module, refreshed pages and ran update.php, but it didn't work.

1
  • There is some discussion on this issue here, but so far without resolution.
    – Nick Hope
    Feb 15, 2018 at 16:13

1 Answer 1

4

Although this question is quite old and no longer relevant for Drupal 8 as drush no longer has entity-updates, I believe people would still be landing on this page with Pending Entity Updates messages in the Status Report. I ran into the same scenario and wanted to address that issue.

The message is shown when the definition of the entity in the database is different from the definition of the entity in the file because of deleting or adding a field in the entity. That is something that is going to happen a lot when you are developing the module and the entity definition keeps evolving.

Uninstalling and installing the module will solve the problem because you are recreating the entity again.

I ran into this same problem and thought I should get to the bottom of this as it was not possible to keep uninstalling and installing the module.

Drush used to have entity-updates as a feature that would allow entity definitions to be updated on the fly. However this was removed from Drupal core in 8.7.0 (Support for entity updates removed from core)

The work around is to install Devel Entity Updates module and run the dentup alternative

If you are using composer

composer require --dev drupal/devel_entity_updates

drush en devel_entity_updates

drush dentup

That should address this problem. The devel entity updates module is to be used in develpment environments only and in higher environments you are expected to push changes to your entities through hook_updates

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.