I am trying to add a new foriegn key in existing table using db_schema.xml but it is not working at all I tried to delete the table and delete module from setup_module table as well but still nothing working.
How I can resolve this issue? Thanks!!
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityBelow is an example of using the foreign key as product id with a custom table.
<table name="custom_tab" resource="default" engine="innodb">
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"/>
<column name="product_id" nullable="true" xsi:type="int" padding="10" identity="false" unsigned="true"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="entity_id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="CUSTOM_TABLE_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID"
table="custom_tab" column="product_id"
referenceTable="catalog_product_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
</table>
Please try like this and inform it is working for you or not ?