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
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:
-
Go to Admin > Stores > Settings > Order Status.
-
Click Create New Status, enter test in all fields, and save.
-
Click Assign Status to State.
- Set Order Status to test.
- Set Order State to Received.
- Save the assignment.
-
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> -
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:
- Adobe Commerce or Magento Open Source on-premises: Quality Patches Tool > Usage in the Quality Patches Tool guide.
- Adobe Commerce on cloud infrastructure: Upgrades and Patches > Apply Patches in the Commerce on Cloud Infrastructure guide.
Related reading
To learn more about Quality Patches Tool, refer to:
- Quality Patches Tool: A self-service tool for quality patches in the Tools guide.