Score:0

Strange "Mismatched entity and/or field definitions" error

tn flag

I know there are plenty of other threads about this but I believe mine is a strange one and I've spent the last day debugging its cause with no luck so far, so hoping someone with more knowledge about schemas/field storage can help me.

First, a little background on what I am doing. I have a set of config which is packaged up using the features module and deployed as a package to a number of our other sites. Part of this feature set are a number of feed types for importing content into nodes. When I deploy this feature on 1 site, I get the "Mismatched entity and/or field definitions" error for the feeds_item field. On the other site I deploy it to, I don't get any error. The fact it errors on one, but not the other is odd.

Mismatched entity and/or field definitions

I traced the issue to SqlContentEntityStorageSchema::requiresFieldStorageSchemaChanges. In particular, what is happening is that the value of $installed_schema is an empty array on the site with the error but has data on the site without the error.

  /**
   * {@inheritdoc}
   */
  public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
    $table_mapping = $this->getTableMapping($this->entityType);

    if (
      $storage_definition->hasCustomStorage() != $original->hasCustomStorage() ||
      $storage_definition->getSchema() != $original->getSchema() ||
      $storage_definition->isRevisionable() != $original->isRevisionable() ||
      $table_mapping->allowsSharedTableStorage($storage_definition) != $table_mapping->allowsSharedTableStorage($original) ||
      $table_mapping->requiresDedicatedTableStorage($storage_definition) != $table_mapping->requiresDedicatedTableStorage($original)
    ) {
      return TRUE;
    }

    if ($storage_definition->hasCustomStorage()) {
      // The field has custom storage, so we don't know if a schema change is
      // needed or not, but since per the initial checks earlier in this
      // function, nothing about the definition changed that we manage, we
      // return FALSE.
      return FALSE;
    }

    $current_schema = $this->getSchemaFromStorageDefinition($storage_definition);
    $this->processFieldStorageSchema($current_schema);
    $installed_schema = $this->loadFieldSchemaData($original);
    $this->processFieldStorageSchema($installed_schema);

    return $current_schema != $installed_schema;
  }

If I check inside the key_value table with these query select * from key_value where collection like 'entity.storage_schema.sql' and name like 'node.field_schema_data.feeds_item'; it is also empty on 1 but not the other:

So, somewhere, somehow the schema hasn't been installed properly on one site. I can fix it by installing the devel-entity-updates module or writing an update hook that simply resaves the existing field storage definition but I'm hoping someone has some insight as to why this is happening. Thankyou!

N.B The site with errors is running on Drupal 9.2.10 while the site without errors is running on 9.2.11 but I'm not sure that makes a difference.

Also, I should point out that the fields are actually installed fine and working. It’s just the mismatch error that is the problem.

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.