Missing hook_install to update field storage definition for menu_link_content

Created on 15 May 2025, about 2 months ago

Problem/Motivation

The hook_install which update field definitions of menu_link_content is missing.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.menu_link_content__menu_item_roles' doesn't exist: SELECT "t".* FROM "menu_link_content__menu_item_roles" "t" WHERE ("entity_id" IN (:db_condition_placeholder_0)) AND ("deleted" = :db_condition_placeholder_1) AND ("langcode" IN (:db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4)) ORDER BY "delta" ASC; Array ( [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => fr [:db_condition_placeholder_3] => und [:db_condition_placeholder_4] => zxx ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1242 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Step to reproduce

  1. Update the core.extension and add menu_item_role_access.
  2. Import the configuration with drush cim.
  3. Notice that the table menu_link_content__menu_item_roles is not present.

Solution

As mentionned is this issue : https://www.drupal.org/node/3034742 β†’ #Updating an existing field storage definition
Since Drupal 8.7, base field is not updated automatically so we need to implement hook_install to update base field definition.
Implement a hook_install() to update the field definitions for menu_link_content.

Remaining task

Test the solution

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @jsimonet
  • Pipeline finished with Success
    about 2 months ago
    Total: 192s
    #498269
  • πŸ‡¬πŸ‡§United Kingdom LiamPower

    Thanks jsimonet - especially for the steps to reproduce. I'll try and test this over the weekend!

  • πŸ‡¬πŸ‡§United Kingdom LiamPower

    @jsimonet what version of Drupal did you get the steps to reproduce on? Following them with a fresh install of Drupal 11 and adding both the module and the module's config file to the exported config adds the table menu_link_content__menu_item_roles

  • @liampower Thank you for your reply.
    I’m confused β€” following your feedback, I can no longer reproduce the issue, even though it was consistently occurring on four different machines and in the test environment.
    I’ll take more time to try and reproduce it, and will provide a detailed procedure if the problem reoccurs.

    The project where the issue occurred was still in Drupal 10.4.3.

  • πŸ‡ΊπŸ‡ΈUnited States fsayoub

    Confirmed. I am on Drupal 10.4.6. This was during a production release. Everything tested out fine on lower environments. Once it hit production, the menu urls were receiving a WSOD.

  • πŸ‡ΊπŸ‡ΈUnited States fsayoub

    @jsimonet β†’ liampower β†’

    Tested the code in the patch and was receiving the same error.

    Steps to reproduce:

    1. Install via composer
    2. Edit menu link to limit to Admin role
    3. Export necessary config
    4. Push to lower envs (where prod database gets cloned down each time a branch is pushed)
    5. Push to prod (where no db is updated)
    6. Receive same error (error from issue reshared for client privacy):

    Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.menu_link_content__menu_item_roles' doesn't exist: SELECT "t".* FROM "menu_link_content__menu_item_roles" "t" WHERE ("entity_id" IN (:db_condition_placeholder_0)) AND ("deleted" = :db_condition_placeholder_1) AND ("langcode" IN (:db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4)) ORDER BY "delta" ASC; Array ( [:db_condition_placeholder_0] => 2 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => fr [:db_condition_placeholder_3] => und [:db_condition_placeholder_4] => zxx ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1242 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    I was also unable to uninstall the module, to bring the site back up. A similar error comes up, regarding base table or view not found.

Production build 0.71.5 2024