{"id":63668,"date":"2016-11-04T14:29:27","date_gmt":"2016-11-04T14:29:27","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=63668"},"modified":"2024-02-21T07:38:47","modified_gmt":"2024-02-21T07:38:47","slug":"delete-existing-foreign-key-magento2-installer","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/","title":{"rendered":"Delete an existing Foreign key in Magento 2 Installer"},"content":{"rendered":"\n<p>If you want to Delete an existing foreign key from a table by using a patch file, then you can use the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\Test\\Setup\\Patch\\Schema;\n\nuse Magento\\Framework\\Setup\\SchemaSetupInterface;\nuse Magento\\Framework\\Setup\\Patch\\PatchVersionInterface;\nuse Magento\\Framework\\Setup\\Patch\\SchemaPatchInterface;\nuse Magento\\Framework\\Setup\\Patch\\DataPatchInterface;\n\nclass DropExistingForeignKey implements SchemaPatchInterface, PatchVersionInterface\n{\n\n    private $schemaSetup;\n\n    public function __construct(\n        SchemaSetupInterface $schemaSetup\n    ) {\n        $this-&gt;schemaSetup = $schemaSetup;\n    }\n\n    public function apply()\n    {\n\n      $this-&gt;schemaSetup-&gt;startSetup();\n      $tableName = $this-&gt;schemaSetup-&gt;getTable(&#039;wk_sellerstorepickup_store_store_view&#039;);\n      \n      $existingForeignKeys = $this-&gt;schemaSetup-&gt;getConnection()-&gt;getForeignKeys($tableName);\n        foreach ($existingForeignKeys as $key) {\n            $this-&gt;schemaSetup-&gt;getConnection()-&gt;dropForeignKey($key&#091;&#039;TABLE_NAME&#039;], $key&#091;&#039;FK_NAME&#039;]);\n      }\n      $this-&gt;schemaSetup-&gt;endSetup();\n    }\n    \/**\n    * Get dependencies\n    *\/\n   public static function getDependencies()\n   {\n       return &#091;];\n   }\n\n     \/**\n     * {@inheritdoc}\n     *\/\n    public static function getVersion()\n    {\n        return &#039;2.0.4&#039;;\n    }\n\n   \/**\n    * Get Aliases\n    *\/\n   public function getAliases()\n   {\n       return &#091;];\n   }\n\n}<\/pre>\n\n\n\n<p>If you want to add a foreign key in your table then refer following blog:<\/p>\n\n\n\n<p><a href=\"http:\/\/webkul.com\/blog\/add-foreign-key-magento2\/\" target=\"_blank\" rel=\"noopener\">Add Foreign Key In Magento2<\/a><\/p>\n\n\n\n<p>I hope this blog will help you with Delete an existing Foreign key in Magento 2 Installer. You may also check our wide range of best <a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noopener\" data-wpel-link=\"internal\">Magento 2 Extensions<\/a>.<\/p>\n\n\n\n<p>Please reach out to our team via a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\" data-wpel-link=\"exclude\">support ticket<\/a>&nbsp;if you have any queries.<\/p>\n\n\n\n<p>Try this and if you have any queries then just comment below \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to Delete an existing foreign key from a table by using a patch file, then you can use the following code: If you want to add a foreign key in your table then refer following blog: Add Foreign Key In Magento2 I hope this blog will help you with Delete an existing <a href=\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":68,"featured_media":60192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,1],"tags":[2070],"class_list":["post-63668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-uncategorized","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Delete an existing Foreign key in Magento 2 Installer<\/title>\n<meta name=\"description\" content=\"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete an existing Foreign key in Magento 2 Installer\" \/>\n<meta property=\"og:description\" content=\"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-04T14:29:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-21T07:38:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bulbul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bulbul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\"},\"author\":{\"name\":\"Bulbul\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\"},\"headline\":\"Delete an existing Foreign key in Magento 2 Installer\",\"datePublished\":\"2016-11-04T14:29:27+00:00\",\"dateModified\":\"2024-02-21T07:38:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\"},\"wordCount\":108,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"Magento2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\",\"url\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\",\"name\":\"Delete an existing Foreign key in Magento 2 Installer\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-11-04T14:29:27+00:00\",\"dateModified\":\"2024-02-21T07:38:47+00:00\",\"description\":\"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Delete an existing Foreign key in Magento 2 Installer\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\",\"name\":\"Bulbul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Bulbul\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/bulbul896\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Delete an existing Foreign key in Magento 2 Installer","description":"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/","og_locale":"en_US","og_type":"article","og_title":"Delete an existing Foreign key in Magento 2 Installer","og_description":"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.","og_url":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-11-04T14:29:27+00:00","article_modified_time":"2024-02-21T07:38:47+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Bulbul","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Bulbul","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/"},"author":{"name":"Bulbul","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e"},"headline":"Delete an existing Foreign key in Magento 2 Installer","datePublished":"2016-11-04T14:29:27+00:00","dateModified":"2024-02-21T07:38:47+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/"},"wordCount":108,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","keywords":["Magento2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/","url":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/","name":"Delete an existing Foreign key in Magento 2 Installer","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","datePublished":"2016-11-04T14:29:27+00:00","dateModified":"2024-02-21T07:38:47+00:00","description":"In this blog we will discuss how to delete an existing foreign key in Magento 2 Installer.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/09\/Magneto-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/delete-existing-foreign-key-magento2-installer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Delete an existing Foreign key in Magento 2 Installer"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e","name":"Bulbul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Bulbul"},"url":"https:\/\/webkul.com\/blog\/author\/bulbul896\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=63668"}],"version-history":[{"count":14,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63668\/revisions"}],"predecessor-version":[{"id":423319,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/63668\/revisions\/423319"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/60192"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=63668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=63668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=63668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}