<table name="profile_products" resource="default" engine="innodb" comment="profile products">
<column xsi:type="smallint" name="id" unsigned="false" nullable="false" identity="true"
comment="ID"/>
<column xsi:type="int" name="product_id" unsigned="true" nullable="false"
identity="false" comment="Product ID"/>
<column xsi:type="int" name="profile_id" nullable="false" comment="Account code"/>
<column xsi:type="int" name="account_id" nullable="false" comment="Account code"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id"/>
</constraint>
<constraint xsi:type="foreign" referenceId="ONBUY_PROFILE_PRODUCT_PROFILE_ID_ONBUY_PROFILE_ID" table="onbuy_profile_products"
column="profile_id" referenceTable="onbuy_profile" referenceColumn="id"
onDelete="CASCADE"/>
<constraint xsi:type="foreign" referenceId="ONBUY_PROFILE_PRD_PRD_ID_CAT_PRD_ENTT_ENTT_ID" table="onbuy_profile_products"
column="product_id" referenceTable="catalog_product_entity" referenceColumn="entity_id"
onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="ONBUY_PROFILE_PRODUCT_PRODUCT_ID_PROFILE_ID">
<column name="profile_id"/>
<column name="product_id"/>
</constraint>
<index referenceId="ONBUY_PROFILE_PRODUCT_PROFILE_ID" indexType="btree">
<column name="profile_id"/>
</index>
<index referenceId="ONBUY_PROFILE_PRD_PRD_ID" indexType="btree">
<column name="product_id"/>
</index>
</table>
-
can you provide more details? behaviors/ errors? commands used?– DianaFeb 17, 2021 at 9:59
1 Answer
Create a foreign key In the following example, the selected constraint node defines the characteristics of the FL_ALLOWED_SEVERITIES foreign key.
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="declarative_table">
<column xsi:type="int" name="id_column" padding="10" unsigned="true" nullable="false" comment="Entity Id"/>
<column xsi:type="int" name="severity" padding="10" unsigned="true" nullable="false" comment="Severity code"/>
<column xsi:type="varchar" name="title" nullable="false" length="255" comment="Title"/>
<column xsi:type="timestamp" name="time_occurred" padding="10" comment="Time of event"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id_column"/>
</constraint>
<constraint xsi:type="foreign" referenceId="FL_ALLOWED_SEVERITIES" table="declarative_table"
column="severity" referenceTable="severities" referenceColumn="severity_identifier"
onDelete="CASCADE"/>
</table>
</schema>
You can also refer to the dev docs.
Thanks