Tuesday 24 September 2019

Drupal 8 - changes were detected in the entity type and field definitions. The % field needs to be updated.

While installing and Uninstalling Modules of Drupal 8 - using the Migrate tool I came across this issue.


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

AND THEN YOU GET A LIST

Something like




I have found two solutions for this , depending on whether this is a mismatched entity or field definition.   So I will list both .  Make sure you have a full backup of your site before you try these.


For Entity mismatches - what we need to do is cleanly remove our Modules, but cannot use the normal way as it gives us an error. 
Here's a lazy one liner.

drush eval "\$module_data = \Drupal::config('core.extension')->get('module'); unset(\$module_data[‘company’]); \Drupal::configFactory()->getEditable('core.extension')->set('module', \$module_data)->save()";

Here the module is called 'company' , you would swap that out for what you wish.php ../vendor/drupal/console/bin/drupal cache:rebuild
And when you've checked the site and are happy we should Export our new configuration 

php ../vendor/drush/drush/drush cex


FIX the FIELD DEFINITION 

That fixes all but the 'Name' field needs to be updated bug. 
For this I had to install this module 
https://www.drupal.org/project/devel_entity_updates
First of all I had to remove the Entity updates module .  You remove this by hand in the composer.json file .  And then run composer again
run composer

Now in the container Enable the module .  

drush pm:enable devel_entity_updates
And run the 'entup' command. 

drush entup


Here are some additional notes that I made while looking for this solution; that may help others find this article. 
I attempted to use updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);


What is the storage_definition for our field

How to find what the storage definition is for a field in Drupal 8. - that leads us here https://www.drupal.org/docs/8/api/entity-api/defining-and-using-content-entity-field-definitions

Drupal 8 get The field storage definition

Drupal 8 Errors found Entity / field definitions the % field needs to be updated hook_update_N getFieldStorageDefinition
Fix Drupal 8 The % field needs to be updated. hook_update_N issue

And then through that search I found that https://www.drupal.org/project/devel_entity_updates