2

This is my db_schema.xml file

<table name="plenty_item_import_item" comment="Plenty Item Import Item Table" engine="innodb" resource="default">
    <column name="entity_id"       xsi:type="int" identity="true" padding="10" unsigned="true" nullable="false" comment="Entity Id" />
    <column name="item_id"         xsi:type="int" padding="10" unsigned="true" comment="Item Id" />
    <column name="variation_id"    xsi:type="int" padding="10" unsigned="true" comment="Variation Id" />
    <constraint xsi:type="primary" referenceId="PRIMARY" >
        <column name="entity_id"/>
    </constraint>
</table>

<table name="plenty_item_import_item_bundle" engine="innodb" resource="default" comment="Plenty Item Import Item Bundle Table">
    <column name="entity_id"           xsi:type="int" padding="10" unsigned="true" nullable="false" identity="true" comment="Entity Id" />
    <column name="variation_bundle_id" xsi:type="int" padding="10" unsigned="true" nullable="true" comment="Variation Bundle Id" />
    <column name="item_id"             xsi:type="int" padding="10" unsigned="true" comment="Item Id" />
    <constraint xsi:type="primary" referenceId="PRIMARY" >
        <column name="entity_id"/>
    </constraint>
    <constraint xsi:type="foreign" referenceId="PLE_IMP_BUN_ITM_PLE_IMP_ITM" 
                table="plenty_item_Import_item_bundle" column="item_id" 
        referenceTable="plenty_item_Import_item" referenceColumn="item_id" onDelete="CASCADE"/>

</table>

In second table I am trying to add a foreign key, in this line

<constraint xsi:type="foreign" referenceId="PLE_IMP_BUN_ITM_PLE_IMP_ITM" 
            table="plenty_item_Import_item_bundle" column="item_id" 
    referenceTable="plenty_item_Import_item" referenceColumn="item_id" onDelete="CASCADE"/>

Now when I run the command

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

to generate db_schema_whitelist.json file, then it was not generating. I checked online for this and I found if there is an issue in db_schema.xml file then json will not generate and I can also debug db_schema.xml file for errors. I got the answer from this link Magento 2 is not generating the db_schema_whitelist.json file via CLI

Now when I checked the errors then it was showing

2019-09-18T15:02:57+00:00 INFO (6): Notice: Undefined index: plenty_item_Import_item in D:\xampp\htdocs\magento-2.2\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php on line 352

It is showing undefined index for plenty_item_Import_item. Now when I remove the line to add the foreign key then it works perfectly. Now my question is How and why it is showing undefined index for plenty_item_Import_item as this table is added at top. I also checked db_scema.xml for catalog module that is present by default and found they have also added a foreign key by same method. Code from db_schema.xml present in module-catalog

<constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_DTIME_ENTT_ID_CAT_PRD_ENTT_ENTT_ID"
                table="catalog_product_entity_datetime" column="entity_id" referenceTable="catalog_product_entity"
                referenceColumn="entity_id" onDelete="CASCADE"/>

1 Answer 1

3

I would guess it is because of your typos in the constraint. Both table names have a capital I for _Import_ instead of a small letter _import_. Nothing else seems to be wrong.

Your Answer

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

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