Magento2 Adding foreign key constraint to a database table

Posted on August 25, 2017
Written by

Adding a foreign key constraint to a database table in Magento2 can be a bit confusing. Here’s a simple example of how to create a table with a foreign key to entity_id in the customer_entity table and entity_id in the catalog_product_entity table. These is also an example here of creating an index for your table.