Score:0

"Mismatched entity and/or field definitions" after enabling contributed module

in flag

I installed the Rabbit Hole module in Drupal 9. I was immediately greeted with this message on the status page:

Mismatched entity and/or field definitions

The following changes were detected in the entity type and field definitions.
User
The Rabbit Hole action field needs to be installed.
The Rabbit Hole redirect path. field needs to be installed.
The Rabbit Hole redirect response code field needs to be installed.
The Rabbit Hole redirect fallback action field needs to be installed.

Everyone seems to say run devel entity-updates, but that module page itself says:

The goal of this module is to have a quick way to apply schema updates while developing new entity types and ending up incrementally adding/removing/changing entity type/field definitions.

When these changes are part of an official release (and not in the scope of a code development session), they should absolutely rely on DB update functions, as explained in the CR above, because that's the only way the entity schema update process can be predictable and reliable.

For this reason, this module depends on Devel and is not meant to be enabled in production environments or relied upon in deployment workflows, see #3082442: Why not meant to be enabled in production environments? for more details.

So, it should not be used or ran in production? Running it locally produces no visible change to configuration exports. So how would you get this done on a production database?

Instead, people say these updates should occur in an update hook. What does that mean? Is this burden on the developer or the user to do? I have seen this from time to time with contributed modules, and do not understand if devel entity-updates will "fix" (correctly fix) this issue, or if there is a concrete way to do this change.

4uk4 avatar
cn flag
You don't need an update hook to install or uninstall a module containing a field definition. The last issue concerning this was solved in Drupal 8.5. See https://www.drupal.org/project/drupal/issues/2282119. Update hooks are for changes in already installed modules.
sonfd avatar
in flag
Does running the entity updates command remove the message from your status page locally?
Score:1
cn flag

You don't get "Mismatched entity and/or field definitions" after installing/uninstalling a contrib module adding base fields to existing entities.

Steps to reproduce:

  • composer require 'drupal/rabbit_hole:^1.0@beta'
  • enable Rabbit Hole main module and Rabbit Hole users submodule
  • the table users_field_data contains the 4 new fields
  • Status page is clear
  • edit a user with individual rabbit hole settings to fill the fields with data
  • check the database, data is stored
  • uninstall the module
  • fields are moved from users_field_data to separate field_deleted_data_* tables
  • run cron
  • field_deleted_data_* are purged from the database

If the module doesn't install/uninstall correctly like this, rollback and test it first on a local copy of the site until it works. Don't use a dev tool like devel entity-updates on production data. Even more so for a module still in beta changing core entity tables.

Kevin avatar
in flag
Is that normal though? Or is this specific to that module?
4uk4 avatar
cn flag
This exact behavior is normal for all modules adding base fields to existing entities.
Kevin avatar
in flag
Odd... I wonder what triggered this message for me. I just recall enabling it.
Score:0
cn flag

I was able to resolve this issue by doing the following:

  1. Note the name(s) of the field(s) in the error message on the status page
  2. Go to /admin/reports/fields and search for the field(s) in question
  3. Click on the link in the "Used In" column for each field in question. That will take you to the "Manage fields" page for the content type where the field is used.
  4. Click "Edit" next to the name of the field in question.
  5. Click "Save" to update the field.

I didn't need to do anything other than click "Save". That resolved the error.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.