Skip to content

Magento Enterprise 2.4.8 (p1 and p2) db_schema.xml contain deployment breaking declarations. #40140

@andy-igoo

Description

@andy-igoo

Preconditions and environment

  • Magento Enterprise versions 2.4.8-p1 and 2.4.8-p2 (I haven't tested 2.4.8)
  • I hit this whilst upgrading from 2.4.7-p5 using composer (require-commerce)

Steps to reproduce

  • Install 2.4.7-p5 via composer to obtain a start point with the schemas
  • Upgrade to 2.4.8-p1for the first example and additionally 2.4.8-p2 where things get worse

Expected result

I can run bin/magento setup:upgrade with no errors

Actual result

"Schema creation/updates" stage throws error: Table catalog_product_entity_media_gallery_value_to_entity do not have column with name entity_id

Additional information

Magento Commerce (Enterprise) 2.4.8-p1

In vendor/magento/module-catalog/etc/db_schema.xml:1679 there is a table declaration with a constraint section that appears unrelated to this table.
The table is catalog_product_entity_media_gallery_value_to_entity:

<table name="catalog_product_entity_media_gallery_value_to_entity" resource="default" engine="innodb"
       comment="Link Media value to Product entity table">
    <column xsi:type="int" name="value_id" unsigned="true" nullable="false" identity="false"
            comment="Value media Entry ID"/>
    <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="false"
            comment="Product Entity ID"/>
    <constraint xsi:type="foreign" referenceId="FK_A6C6C8FAA386736921D3A7C4B50B1185"
                table="catalog_product_entity_media_gallery_value_to_entity" column="value_id"
                referenceTable="catalog_product_entity_media_gallery" referenceColumn="value_id"
                onDelete="CASCADE"/>
    <constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_ENTT_ID_CAT_PRD_ENTT_ENTT_ID"
                table="catalog_product_entity_media_gallery_value_to_entity" column="entity_id"
                referenceTable="catalog_product_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
    <constraint xsi:type="primary" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_VAL_ID_ENTT_ID">
        <column name="value_id"/>
        <column name="entity_id"/>
    </constraint>

    <!-- This constraint appears unrelated to this table. Commenting it out avoids the error. -->
    <constraint xsi:type="unique" referenceId="CAT_PRD_IDX_PRICE_TMP_ENTT_ID_CSTR_GROUP_ID_WS_ID">
        <column name="entity_id"/>
        <column name="customer_group_id"/>
        <column name="website_id"/>
    </constraint>
</table>

Issues with this constraint:

  • Columns customer_group_id and website_id do not exist in this table.
  • Adding this constraint causes bin/magento setup:upgrade to fail with:
    Table catalog_product_entity_media_gallery_value_to_entity do not have column with name entity_id
    

Additionally, in vendor/magento/module-catalog-staging/etc/db_schema.xml:256, the same table is modified to disable entity_id and replace it with row_id:

<table name="catalog_product_entity_media_gallery_value_to_entity" resource="default"
       comment="Link Media value to Product entity table">

    <!-- entity_id is disabled here -->
    <column xsi:type="int" name="entity_id" disabled="true"/>
    <column xsi:type="int" name="row_id" unsigned="true" nullable="false" identity="false"
            onCreate="migrateDataFrom(entity_id)" comment="Version Id"/>
    <constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_ENTT_ID_CAT_PRD_ENTT_ENTT_ID"
                disabled="1"/>
    <constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_ROW_ID_CAT_PRD_ENTT_ROW_ID"
                table="catalog_product_entity_media_gallery_value_to_entity" column="row_id"
                referenceTable="catalog_product_entity" referenceColumn="row_id" onDelete="CASCADE"/>
    <constraint xsi:type="primary" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_VAL_ID_ENTT_ID" disabled="1"/>
    <constraint xsi:type="primary" referenceId="CAT_PRD_ENTT_MDA_GLR_VAL_TO_ENTT_VAL_ID_ROW_ID">
        <column name="value_id"/>
        <column name="row_id"/>
    </constraint>
</table>

Conflict:

  • module-catalog expects entity_id (and defines constraints referencing it).
  • module-catalog-staging disables entity_id.
  • The unique constraint in module-catalog still references entity_id along with two other non-existent columns.
  • This results in a schema that cannot be created.

Magento Commerce (Enterprise) 2.4.8-p2

In 2.4.8-p2, the same “extra” unique constraint appears twice in vendor/magento/module-catalog/etc/db_schema.xml:1696:

<constraint xsi:type="unique" referenceId="CAT_PRD_IDX_PRICE_TMP_ENTT_ID_CSTR_GROUP_ID_WS_ID">
    <column name="entity_id"/>
    <column name="customer_group_id"/>
    <column name="website_id"/>
</constraint>
<constraint xsi:type="unique" referenceId="CAT_PRD_IDX_PRICE_TMP_ENTT_ID_CSTR_GROUP_ID_WS_ID">
    <column name="entity_id"/>
    <column name="customer_group_id"/>
    <column name="website_id"/>
</constraint>

Notes:

  • The constraint is still invalid for this table.
  • The fact that it appears twice may indicate over reliance on AI, a merge problem or copy-paste mishap in the XML source.

Summary

  • Both modules together define a table schema that cannot be installed:

    1. module-catalog requires entity_id.
    2. module-catalog-staging removes entity_id.
    3. A unique constraint in module-catalog references entity_id, customer_group_id, and website_id — two of which do not exist in this table.
    4. In 2.4.8-p2, the invalid constraint appears twice.
  • This prevents running bin/magento setup:upgrade successfully and blocks upgrades.

  • We cannot proceed with upgrading to these versions until this conflict is resolved.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions