Drupal 8: Mismatched entity and/or field definitio

2019-09-10 02:57发布

问题:

While trying to understand why my view is not displaying, I noticed the following error in the log:

I do not think it is possible to delete the URL alias from Taxonomy terms. At least I cannot find how to do this. I have, however gone through ALL of my taxonomy terms and removed the value for this field.

I have also done the following with Pathauto:

Also, I have checked the report located at admin/reports/fields and can confirm that there are no entities that use a field called URL alias.

I have gone through each content item and ensured that they have the following setting (anyone know how to do this in bulk?). But still the error remains.

Anyone know then how I can fix this strange error?

回答1:

Im not entirely sure what this command does, but it fixed the error:

drush updb --entity-updates


回答2:

Since https://www.drupal.org/node/2554097, the magic in Drupal core that took care of updating entity definitions is gone. drush updb --entiy-updates is an alternative to this but it is not a silver bullet. Instead, it is safer to write database updates.

Taking the screenshot at the top as an example, here is a database update that would delete those two field definitions:

/**
 * Fix taxonomy and node field definitions.
 *
 */
function mymodule_update_8101() {
  $manager = \Drupal::entityDefinitionUpdateManager();

  if ($field = $manager->getFieldStorageDefinition('alias', 'node')) {
    $manager->uninstallFieldStorageDefinition($field);
  }

  if ($field = $manager->getFieldStorageDefinition('alias', 'term')) {
    $manager->uninstallFieldStorageDefinition($field);
  }
}

Have a look at the rest of the available methods at https://www.drupal.org/node/2554097 in order to write database updates for each scenario.