Mismatched entity and/or field definitions: node.layout_builder__layout field

Created on 1 February 2022, over 2 years ago
Updated 22 January 2024, 9 months ago

Problem/Motivation

Starting in August 2021, I have had an error on the Status Report page of my Drupal 9 website. The error states

Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Content

The node.layout_builder__layout field needs to be updated

When I noticed the error (August 18, 2021), I took notes of what changes had occurred to the site and ran some tests with previous site backups:

  • I had just updated from Drupal 9.2.0 to Drupal 9.2.4 when I noticed the error appear. I restored a backup of the Drupal 9.2.0 site from August 17 and the error was still present
  • I had just uninstalled the Bootstrap Layouts module. During testing, I reproduced the issue while Drupal Layouts was still installed. The module is installed now, so I must have left it installed again (this was a surprise to me as I was typing this post).
  • I restored my backup from August 4, 2021 and the error was absent from the Status Report page. The error was still absent after applying all pending module and database updates. From my notes, I made the following changes between August 4 and August 18:
    • Uninstalled the "Bootstrap Layouts" module
    • Installed the "Simple XML Sitemap" module and changed relevant settings
    • Installed font-related modules and changed relevant settings
    • Added links to the main menu
  • Also while testing the August 4 backup, I installed a newly available update for the commerce_pricelist module. After installing the update, the error appeared. I assume this was coincidence, so I'm not sure what the real cause was.

More recently, a fatal error occurred after I edited the layout of a Commerce product type. I unfortunately didn't copy the error, but I believe it is related to this Entity/Field mismatch error. This has been my motivation for trying to fix the Mismatched Entity/Field definition error.

Since then, I have tried disabling "Use Layout Builder" on all content types, then enabling it again and recreating the layouts. Disabling that option caused the error to disappear from the product page. However, after recreating the layout for my front page, the error appeared again.

I have tried to reproduce the error on a local testsite, but it appears very inconsistently. I believe that I followed the exact same procedure 3 times (restoring from the same DB backup each time), and the error only appeared the first time. Even more odd, the error was absent until I ran cron, after which it appeared. I have been running cron after each change in subsequent tests, but I cannot get the error to manifest again.

I have two questions here:

  1. Is there anything else that I should do to try to reproduce, and hopefully fix, the error?
  2. Is it safe to use the devel entity updates module to correct the error in this case. I hesitate to use that module because it is "not meant to be enabled in production environments".

Steps to reproduce

Unknown. The issue is difficult to reproduce, though the error has remained on my Status Report page for over 6 months.

Relevant site information

Related modules that are currently installed:

  • Layout Builder
  • Layout Discovery
  • Bootstrap Layouts
  • Bootstrap Layout Builder
  • Bootstrap Styles
  • Layout Builder Blocks
  • Layout Builder Restrictions
πŸ’¬ Support request
Status

Closed: outdated

Version

9.4

Component
Layout builderΒ  β†’

Last updated about 8 hours ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium flyke

    I just updated everything in a project (core to 9.5.11 and modules to latest stable release), ran all updates (drush updb) with success and without notices, and I now see this at admin/reports/status.
    My project is in Dutch but its the same error as in the issue summary.

    Niet overeenkomende entiteit en/of velddefinities
    De volgende wijzigingen werden gevonden in het entiteitstype en de velddefinities.
    Content
    Het veld node.layout_builder__layout moet bijgewerkt worden.

    So, as was mentioned in this issue, I edited my content types that have layoutbuilder, go to Manage fields and look at the layoutbuilder field.
    It is locked, so I cannot edit and save the field via the Operations column.
    So I click in the column Field type on 'layout section' for the layoutbuilder field.
    But when I click save, I get the notice:
    The SQL storage cannot change the schema for an existing field (layout_builder__layout in node entity) with data..
    So I can not (re) save to fix this error. I also have installed the devel_entity_updates module so I can use
    drush entup
    But that also results in the same:

    In SqlContentEntityStorageSchema.php line 1756:
                                                                                                                         
      The SQL storage cannot change the schema for an existing field (layout_builder__layout in node entity) with data.

    Maybe somewhere some update hook did have a problem somewhere but I cannot see or find it. Not sure on how to fix this issue at the moment.

  • πŸ‡§πŸ‡ͺBelgium flyke

    In order to get more info, I edited web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php and changed line 1755 to:

          if ($this->hasColumnChanges($storage_definition, $original)) {
            dpm($original);
            dpm($storage_definition);
            throw new FieldStorageDefinitionUpdateForbiddenException('The SQL storage cannot change the schema for an existing field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data.');
          }

    So I can at least see the difference between the original and the new definition.
    I now know that the cause is something somewhere is trying to add propertyDefinitions to the storage definition that weren't there before.

  • πŸ‡§πŸ‡ͺBelgium flyke

    I was able to get more precise info on what on earth is changed in node.layout_builder__layout by editing the hasColumnChanges function inside core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php line 2487 to:

              if ($definition_spec != $stored_spec) {
                dpm($definition_spec);
                dpm($stored_spec);
                return TRUE;
              }

    That shows me that the blob size was changed somewhere. Either from 'normal' to 'big' or from 'big' to 'normal'. Still doing some digging and trying to understand the cause, the source and maybe find a solution.
    I searched my database for 'layout_builder__layout' and found the 'node__layout_builder__layout' table.
    Inside that, there is a layout_builder__layout_section field of type 'longblob' that I suspect is very related.
    The search goes on.

  • πŸ‡§πŸ‡ͺBelgium flyke

    I had the same error in my status report on a project I just upgraded to Drupal 10.2. (Might have been there before the update, but only checked the status messages after the update to Drupal 10).

    Adding patch from #3030154 in my composer.json (and then performing drush updb) made the error go away.

    "patches": {
                "drupal/core": {
                    ...
                    "#3030154": "https://www.drupal.org/files/issues/2023-04-06/3030154-62_0.patch"
                },
Production build 0.71.5 2024