Skip to content

db_schema can’t set foreign key – Table [prefix]_sales_order do not have column with name “name”

I must add column1 to sales_order_grid and create foreign key to
table sales_grid.column1
When i try use bin/magento setup:upgrade i get next message

Table [myPrefix]_sales_order do not have column with name “name1”

In fact, the column exists and I do not confuse names and uppercases

module.xml

<module name="Vendor_ModuleName">
    <sequence>
        <module name="Magento_Backend"/>
        <module name="Magento_Ui"/>
    </sequence>
</module>

db_schema.xml

<table name="sales_order_grid">
    <column xsi:type="boolean" name="name"/>
    <constraint xsi:type="foreign" referenceId="SALES_ORDER_GRID_NAME_SALES_ORDER_NAME" table="sales_order_grid" column="name" referenceTable="sales_order" referenceColumn="nameRef" onDelete="CASCADE"/>
</table>

di.xml

<virtualType name="MagentoSalesModelResourceModelOrderGrid" type="MagentoSalesModelResourceModelGrid">
    <arguments>
        <argument name="columns" xsi:type="array">
            <item name="name" xsi:type="string">sales_order.label_Name</item>
        </argument>
    </arguments>
</virtualType>

other info:

docker images:

  1. mariaDB – mariadb:10.4
  2. nginx – markoshust/magento-nginx:1.18-7
  3. php-fpm – markoshust/magento-php:7.3-fpm-12