3

I have developed a custom Drupal field.

All works fine. We are already using the field in production for a year. But the status report for exactly this field says:

Mismatched entity and/or field definitions

I would like to get rid of that message. It gives me a bad feeling about the reliability of my Drupal installation.

I could write an update hook if I knew in detail what is wrong.

How can I find out what exactly does not match?

2
  • 1
    It's unclear why you want to get rid of this message. Normally you develop a new module and then deploy it, which means install the module in different environments and import configurations. If this is about an already deployed module you need an update hook for the database schema updates. If you want to get rid of this message in your dev environment you can either re-install the module or use drupal.org/project/devel_entity_updates
    – 4uk4
    Sep 15, 2021 at 7:57
  • Thanks for you comment, @4k4. I have edited my answer and explained that the field is in use in production and that the error message makes me fear that the Drupal installation is not reliable. Sep 15, 2021 at 8:47

1 Answer 1

3

OK, if this happened in production you probably had a code change in FieldItemInterface::schema().

The most detailed information you get is from

\Drupal::entityDefinitionUpdateManager()->getChangeList()

returning a list of entity fields affected and the status 1,2 or 3. If your field is listed with 2 (DEFINITION_UPDATED) then check your code history for schema changes. If you don't have a code history you could check the current state of the database table(s). If you don't see the changes then install the module on a fresh site and compare the created tables.

2
  • If you're using a debugger, \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::requiresFieldStorageSchemaChanges() can be a good place to set a breakpoint for more details.
    – Andy
    Sep 13 at 10:27
  • Spooky timing, I completely randomly saw this being promoted in Slack: drupal.org/project/schema_diff
    – Andy
    Sep 13 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.