Delete an existing Foreign key Magento2 installer

If you want to Delete an existing foreign key from a table by installer, then you can use following code:


namespace Webkul\Test\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

 * @codeCoverageIgnore
class UpgradeSchema implements UpgradeSchemaInterface
     * {@inheritdoc}
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)




wk_child_table is the table name in which you created a foreign key column.

wk_main_table is the table which you used for reference.

entity_id is the foreign key column name of  “wk_child_table”.

main_id is the referenced column of table “wk_main_table”.


If you want to add a foreign key in your table then refer following blog:

Add Foreign Key In Magento2


Hope it will help you.

Thank you.

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again