ACSD-60989: Modifying a column with a foreign key through declarative schema causes errors on MariaDB

The ACSD-60989 patch fixes the issue where modifying a column with a foreign key via declarative schema on MariaDB causes setup upgrade errors due to foreign key constraints. This patch is available when the Quality Patches Tool (QPT) 1.1.78 is installed. The patch ID is ACSD-60989. Please note that this issue was fixed in Adobe Commerce 2.4.8.

Affected products and versions

The patch is created for Adobe Commerce version:

  • Adobe Commerce (all deployment methods) 2.4.6-p6

Compatible with Adobe Commerce versions:

  • Adobe Commerce (all deployment methods) >=2.4.4 <2.4.8
NOTE
The patch might become applicable to other versions with new Quality Patches Tool releases. To check if the patch is compatible with your Adobe Commerce version, update the magento/quality-patches package to the latest version and check the compatibility on the Quality Patches Tool: Search for patches page. Use the patch ID as a search keyword to locate the patch.

Issue

Modifying a column with a foreign key via declarative schema on MariaDB fails due to foreign key constraint errors during setup upgrade.

Steps to reproduce:

  1. Go to Admin > Stores > Settings > Order Status.

  2. Click Create New Status, enter test in all fields, and save.

  3. Click Assign Status to State.

    1. Set Order Status to test.
    2. Set Order State to Received.
    3. Save the assignment.
  4. Create, register, and enable a custom module, and add the following to db_schema.xml:

    code language-none
    <?xml version="1.0"?>
    <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/etc/db_schema.xsd">
        <table name="sales_order_status">
            <column xsi:type="varchar" name="status" nullable="false" length="64" comment="Order Status"/>
        </table>
        <table name="sales_order_status_state">
            <column xsi:type="varchar" name="status" nullable="false" length="64" comment="Order Status"/>
        </table>
        <table name="sales_order_status_label">
            <column xsi:type="varchar" name="status" nullable="false" length="64" comment="Order Status"/>
        </table>
    </schema>
    
  5. Run the following command:

    code language-none
    bin/magento setup:upgrade
    

Expected results:

The setup upgrade completes successfully without foreign key constraint errors.

Actual results:

An error occurs during the setup upgrade:

Unable to apply patch Vendor\Sales\Setup\Patch\Schema\DataPatch for module Vendor_Sales.
Original exception message:
SQLSTATE[HY000]: General error: 1833 Cannot change column 'status': used in a foreign key constraint
'SALES_ORDER_STATUS_LABEL_STATUS_SALES_ORDER_STATUS_STATUS'
of table 'sales_order_status_label'

Apply the patch

To apply individual patches, use the following links depending on your deployment method:

To learn more about Quality Patches Tool, refer to:

recommendation-more-help
commerce-operations-help-tools