Вопрос

In a module we're developing we declare a new database table with a foreign key relationship to the sales_order table. We want to support Magento 2.3 and 2.4, so we use the declarative schema (db_schema.xml).

The schema looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="my_order_table" resource="default" engine="innodb">
        <column xsi:type="int" unsigned="true" nullable="false" name="sales_order_id" padding="10" />
        <!-- extra columns, including a PK -->
        <constraint xsi:type="foreign" referenceId="MY_ORDER_SALES_ORDER_ID" table="my_order_table" column="sales_order_id" referenceTable="sales_order" referenceColumn="entity_id" />
    </table>
</schema>

So the column my_order_table.sales_order_id references Magento's sales_order.entity_id, and all is well. As long as we use Magento 2.4, because for 2.3 their own declaration is different. Compare:

Magento 2.3:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="sales_order" resource="sales" engine="innodb" comment="Sales Flat Order">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>

Magento 2.4:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="sales_order" resource="sales" engine="innodb" comment="Sales Flat Order">
        <column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true"
                comment="Entity ID"/>

In 2.3, there's the padding="10" attribute on the column, which is gone in 2.4. If we add that same attribute to our schema, it works in both 2.3 (on MariaDB 10.3) and 2.4 (on MySQL 5.7). If we omit that padding, it works in 2.4 but in 2.3 gives the error while running setup:upgrade:

Column definition "sales_order_id" and reference column definition "entity_id" are different in tables "my_order_table" and "sales_order"

This attribute was removed in a commit named "MC-14884: MySQL-8 and MariaDB-10.4 support".

So my question is: why does it work if we declare the referencing column with padding, and what problems can that cause on later upgrades? Is it related to MariaDB?

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top