I have this db_schema.xml

<?xml version="1.0"?>
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <!-- Setup table vendor_shipping_option -->
    <table name="vendor_shipping_option" resource="default" engine="innodb">
        <column name="rate_id" xsi:type="int" padding="10" unsigned="true" nullable="false" identity="true" comment="Entity ID" />
        <column name="name" xsi:type="varchar" length="255" nullable="true" comment="Name" />
        <column name="description" xsi:type="text" nullable="true" comment="Description" />
        <column name="type" xsi:type="varchar" length="255" nullable="true" comment="Type" />
        <column name="source" xsi:type="varchar" length="255" nullable="true" comment="Source" />
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="rate_id" />
        <constraint xsi:type="foreign" referenceId="VENDORSHIPPING_SOURCE_INVENTORY_SOURCE_SOURCE_CODE" table="vendor_shipping_option" column="source" referenceTable="inventory_source" referenceColumn="source_code" onDelete="CASCADE" />

    <!-- Setup table vendor_shipping_click_and_collect_availability -->
    <table name="vendor_shipping_click_and_collect_availability" resource="default" engine="innodb">
        <column name="rate_id" xsi:type="int" padding="10" unsigned="true" nullable="false" comment="Entity ID" />
        <column name="click_and_collect_window_id" xsi:type="int" padding="10" unsigned="true" nullable="true" comment="Click And Collect Window Id"/>
        <column name="day" xsi:type="varchar" length="255" nullable="true" comment="Day" />
        <column name="delivery_hours" xsi:type="varchar" length="255" nullable="true" comment="Delivery Hours" />
        <column name="start" xsi:type="datetime" on_update="false" nullable="true" comment="Start"/>
        <column name="end" xsi:type="datetime" on_update="false" nullable="true" comment="End"/>
        <constraint xsi:type="foreign" referenceId="VENDORSHIPPING_CAC_AVAI_RATE_ID_VENDORSHIPPING_RATE_ID" table="vendor_shipping_click_and_collect_availability" column="rate_id" referenceTable="vendor_shipping_option" referenceColumn="rate_id" onDelete="CASCADE" />

Then i run setup command, and in db i got foreign key VENDORSHIPPING_CAC_AVAI_RATE_ID_VENDORSHIPPING_RATE_ID changed to FK_A9DDDF3AAD5A318C723BEEE21737E6A0.

enter image description here

Does anyone know how to resolve this problem?

  • Your file is up-to-date there are no issues when running the command. if an error then deletes both tables from DB and Again run the upgrade command or you can also change your referenceId.
    – Msquare
    Commented Dec 3, 2021 at 10:45
  • @Msquare i've follow your instruction, but not working, do you have other solutions?
    – fudu
    Commented Dec 6, 2021 at 9:54

1 Answer 1


Delete Your Table and remove your module entry from the "setup_module" table

now run php bin/magento setup:upgrade

then run php bin/magento setup:db-declaration:generate-whitelist --module-name=Vendor_Module

  • sorry for late reply, but it doesn't work, do you have other solutions?
    – fudu
    Commented Dec 6, 2021 at 9:51
  • I think you are using wrong logic of creating foreign key constrains so this is causing, please compare logic syntax from magento2 schema. Commented Dec 6, 2021 at 17:40
  • @ZahidH can you tell more detail about this? with the same syntax, i've successfully in created 3 other tables that have foreign key.
    – fudu
    Commented Dec 21, 2021 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.