Problem/Motivation
The Status report (/admin/reports/status#error) generates the following error:
The 'Status report' on /admin/reports/status gives the following message under 'Status details / Errors found':
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 From state field needs to be updated.
- The To state field needs to be updated.
Workflow transition
- The From state field needs to be updated.
- The To state field needs to be updated.
How to fix that?
Steps to reproduce
- install Workflow 8.x-1.0
- update to Workflow 8.x-1.8 or higher (or lower)
- check the report
Proposed resolution
This is because changes/improvements are done on the Workflow Fields.
However, changes schema/field definitions are not (completely) supported by Drupal core.
See for example core issue #2643308: Stale field settings used by options_allowed_values prevents widgets from updating the allowed values.
In the past, schema updates were applied by Drupal core upon module update.
However, at some point in time, that was revoked. See the following change records:
- update.php will not automatically update entity schemas anymore
- Write update functions for entity schema updates, automation removed outlines the steps to take.
Remaining tasks
1. update the schema/field definition.
- See function WorkflowTransition::baseFieldDefinitions();
- See function WorkflowItem::propertyDefinitions() and the settingsForm;
The following contrib module issue contains an example:
- https://www.drupal.org/project/2157705/issues/3155488#comment-14143361
The following core issue:
- #2601762: Mismatched entity and/or field definitions after upgrade from RC1 to RC2
2. Remove the 'target_id' code from WorkflowTransition::save();
Comments
Comment #2
johnvThis 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:
Comment #3
johnvExcuting the above gives the following result:
Comment #4
dabley commentedI 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?
Comment #5
dabley commentedComment #6
johnvMy 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??
Comment #7
dabley commentedI 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.
Comment #8
dabley commentedJohnv, 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.
Comment #9
johnvThere is no patch attached, hence back to active.
Comment #10
geek-merlinLooks like an update issue. And unclear if still an issue.
Comment #11
aswathyajish commentedThis 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 :
I tried to run drush entity-updates command, but the following error is shown :
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?
Comment #12
aswathyajish commentedComment #13
johnvSee this core change record about this message: update.php will not automatically update entity schemas anymore
Maintainer, the change notice at Write update functions for entity schema updates, automation removed outlines the steps you need to take.
Comment #14
dabley commentedAswathyAjish - did you try the workaround I posted?
Comment #15
johnvComment #16
e5sego commentedFor me, the workaround from https://www.drupal.org/project/2157705/issues/3155488#comment-14143361 worked with existing content.
Comment #17
keshavv commentedThe 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;
}
Comment #18
johnvUpdated summary with latest status.
Comment #19
johnvComment #20
johnvAdded a 'remaining task'.
Comment #23
johnv