The Status report (/admin/reports/status#error) generates the following error:

Errors found: ENTITY/FIELD DEFINITIONS
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Workflow scheduled transition > The Workflow scheduled transition entity type needs to be updated.
Workflow executed transition > The Workflow executed transition entity type needs to be updated.

How to do that?

Comments

johnv created an issue. See original summary.

johnv’s picture

This is also reported here: #2601762: Mismatched entity and/or field definitions after upgrade from RC1 to RC2
And gives the following resolutions:
- drush entity-updates
- add PHP:

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

Status: Active » Closed (won't fix)

Excuting the above gives the following result:

Update #8002

Failed: Drupal\Core\Entity\EntityStorageException: The SQL storage cannot change the schema for an existing entity type (workflow_transition) with data. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate() (line 322 of ...\core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema.php).
dabley’s picture

I ran drush entity-updates, and this successfully updated "Workflow scheduled transition", but failed to update "Workflow executed transition" - and that's because my workflow_transition_schedule table is empty, while my workflow_transition_history table has data in it.
I realise that the issue of not being able to update storage definitions of entity types that already have some data is a generic problem for Drupal 8. However, I would appreciate some advice from those who are more knowledgeable than me. When the 'Mismatched entity and/or field definitions' error message is shown in the status report, even after running drush entity-updates, what should users do?

  1. Ignore the error, keep fingers crossed, and hope for the best?
  2. Export data from the offending table, truncate the table, re-run entity-updates, then re-import?
  3. Update the table (and other?) definitions using appropriate SQL commands to bring the storage spec up to date?
  4. Uninstall the Workflow Module, ensure all its data and tables are deleted, and then reinstall it from scratch?
  5. Something else?
dabley’s picture

Status: Closed (won't fix) » Needs work
johnv’s picture

My test system also shows these errors, but there does not seem to be any problem.
Perhaps an explcite DB update is necessary in an update_hook??

dabley’s picture

Status: Needs work » Needs review

I found that the following is a workaround for this error:

1. Make a backup copy of workflow_transition_history table. This can be done by exporting the table, e.g. in PHPMyadmin, or by running SQL such as:
Create table bak_workflow_transition_history as select * FROM workflow_transition_history;
2. Delete all the rows in the table. e.g. with the SQL:
Truncate table workflow_transition_history;
3. Run drush entity-updates. This should complete without error. I found no change in the definition of the table.
4. Re-import the data back into the table, e.g. by importing, or running SQL such as:
Insert into workflow_transition_history select * from bak_workflow_transition_history;
5. Get rid of the backup table:
Drop table bak_workflow_transition_history;

Running the admin status report now shows there's no longer an error.

I am unable to test that the re-imported data functions correctly, as the Workflow module doesnt currently support a History Tab for entities other than Nodes and Taxonomy terms (and my workflow is not on one of these entities).

I was surprised that after running "drush entity-updates" the table definition remained exactly the same, as far as I could see. I wonder what actually got updated? (I also ran a "drush cex" - but this showed nothing to have changed either.)

In my case, I had no rows in the workflow_transition_schedule table, so I didnt need to do anything special with that. But if you do have rows in that table, the above approach might also work. (I have compared the pre- and post-update table definitions, and they look the same too.)

Others' perspectives on this would be welcome.

dabley’s picture

My test system also shows these errors, but there does not seem to be any problem.
Perhaps an explcite DB update is necessary in an update_hook??

Johnv, yes, I can well believe that there are no functional problems - but I dont feel happy simply ignoring an error message. Especially if a client takes a look at the status report, and gets the impression that I'm exposing them to risk.

This issue https://www.drupal.org/project/drupal/issues/2542748 from two years ago (and marked as Fixed) discusses the generic problem. I haven't read all the comments in that post, but the thrust seems to be that modules should supply their own hook_update_N() functions in order to run entity schema updates.

So, it seems to me that a proper solution would - as you say - be for the Workflow module to have a suitably implemented hook_update_N() function.

johnv’s picture

Status: Needs review » Active

There is no patch attached, hence back to active.

geek-merlin’s picture

Status: Active » Postponed (maintainer needs more info)

Looks like an update issue. And unclear if still an issue.

AswathyAjish’s picture

This issue still exist.

My drupal version is 8.6.1 and my workflow module version is 8.x-1.1. Now I have upgraded my PHP version to 7. Then the following error message is shown in the status report :

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

The Workflow transition entity type needs to be updated.

Workflow scheduled transition

The Workflow scheduled transition entity type needs to be updated.

I tried to run drush entity-updates command, but the following error is shown :

Drupal\Core\Entity\EntityStorageException: The SQL storage cannot [error]
change the schema for an existing entity type (workflow_transition)
with data. in
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate()
(line 347 of
/opt/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).
Failed: Drupal\Core\Entity\EntityStorageException: !message in [error]
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate()
(line 347 of
/opt/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).

Then I deleted all nodes of the workflow entity type and tried to execute drush entity-updates command. Then it executed successfully and the error message from status report is gone. (I have done this in my development server)

But I could not delete the nodes in my production server, so is there any option to execute drush entity-updates command without deleting the existing nodes?

AswathyAjish’s picture

Status: Postponed (maintainer needs more info) » Active
johnv’s picture

See this change record abut this message: https://www.drupal.org/node/2554101
Maintainer, the change notice at https://www.drupal.org/node/2554097 outlines the steps you need to take.

dabley’s picture

AswathyAjish - did you try the workaround I posted?

johnv’s picture

Category: Bug report » Support request
e5sego’s picture

For me, the workaround from https://www.drupal.org/project/2157705/issues/3155488#comment-14143361 worked with existing content.

keshavv’s picture

Status: Active » Needs review

The solution mentioned in #16 works for me. Here is the short snippet.
Execute this code in an update hook.

$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;
}