6

I just try to override db_schema.xml file of a core customer module into my custom module , but there is no success.

I need to remove a constraint defined in customer db_schema.xml file, how may I do that.

Thanks

7
  • Could you share the code with overided file path..
    – aravind
    Commented Oct 30, 2019 at 4:49
  • @aravind, I just have copied the file from vendor\module-customer\etc\db_schema.xml to my custom moulde <NAMESPACE>\<MODULE>\etc\db_schema.xml and did necessary changes regarding constrants, is any thing else I need to do ? Commented Oct 30, 2019 at 4:54
  • NO this is the way..Have you run the whitelist command?
    – aravind
    Commented Oct 30, 2019 at 4:57
  • @aravind, I run command and the changes made I can see their in file, but still no hope. Commented Oct 30, 2019 at 4:58
  • In which table did you change the constraint?and column name?
    – aravind
    Commented Oct 30, 2019 at 5:00

2 Answers 2

5

After setting disabled="true" to the constraint, run generate whitelist command and upgrade.

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="customer_entity">    
        <constraint xsi:type="unique" referenceId="CUSTOMER_ENTITY_EMAIL_WEBSITE_ID" disabled="true" />        
    </table>
</schema>
5
  • Could you Check now..I have updated the answer..
    – aravind
    Commented Oct 30, 2019 at 5:17
  • 1
    To simplify your file: for <table>, you only need the name attribute. For the constraint, only xsi:type, referenceId and disable. You don't need to copy all those other attributes. Commented May 1, 2020 at 18:07
  • 1
    Yes @thedotwriter i have updated it..
    – aravind
    Commented May 2, 2020 at 4:18
  • Just so people are aware, this only seems to work once the table has been completely removed. Make sure to take a backup of any table you are modifying, DROP <tablename>, setup:upgrade then restore that tables data (if it's something important) Commented Aug 26, 2020 at 7:16
  • Does not work, the constraint is still there.
    – Black
    Commented Jul 27, 2022 at 13:54
0

I had to disable the constraint below and this is how I solved it:

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="company_configurator_configurations" resource="default"

        ...

        <constraint xsi:type="foreign" referenceId="COMPANY_CONFIGURATOR_CONFIGURATIONS_QUOTE_ITEM_ID_QUOTE_ITEM_ITEM_ID"
            table="company_configurator_configurations"
            column="quote_item_id"
            referenceTable="quote_item"
            referenceColumn="item_id"
            onDelete="CASCADE"
        />

        ...

Solution:

Set disabled="true":

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="company_configurator_configurations" resource="default"

        ...

        <constraint xsi:type="foreign" referenceId="COMPANY_CONFIGURATOR_CONFIGURATIONS_QUOTE_ITEM_ID_QUOTE_ITEM_ITEM_ID"
            table="company_configurator_configurations"
            column="quote_item_id"
            referenceTable="quote_item"
            referenceColumn="item_id"
            onDelete="CASCADE"
            disabled="true"
        />

        ...

Generate whitelist for the module:

bin/magento setup:db-declaration:generate-whitelist --module-name=Company_Configurator

Setup Upgrade

bin/magento setup:upgrade --keep-generated

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.