{"id":4603,"date":"2018-11-20T07:41:18","date_gmt":"2018-11-20T07:41:18","guid":{"rendered":"https:\/\/www.codebee.co.th\/labs\/?p=4603"},"modified":"2020-10-14T07:28:25","modified_gmt":"2020-10-14T07:28:25","slug":"%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%81%e0%b8%81%e0%b9%89-error-foreign-key-constraint-incorrectly-formed","status":"publish","type":"post","link":"https:\/\/www.codebee.co.th\/labs\/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%81%e0%b8%81%e0%b9%89-error-foreign-key-constraint-incorrectly-formed\/","title":{"rendered":"\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint \u0e43\u0e19 MySQL"},"content":{"rendered":"<h2>\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint \u0e43\u0e19 MySQL<\/h2>\n<p>\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint is incorrectly formed<br \/>\n<strong>\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint is incorrectly formed<\/strong><br \/>\n\u0e2a\u0e32\u0e40\u0e2b\u0e15\u0e38\u0e02\u0e2d\u0e07 error \u0e40\u0e01\u0e34\u0e14\u0e08\u0e32\u0e01\u0e01\u0e32\u0e23\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e1e\u0e22\u0e32\u0e22\u0e32\u0e21\u0e17\u0e35\u0e48\u0e08\u0e30\u0e2a\u0e23\u0e49\u0e32\u0e07 table \u0e2b\u0e23\u0e37\u0e2d\u0e40\u0e1e\u0e34\u0e48\u0e21 row data \u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b\u0e43\u0e19\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e41\u0e15\u0e48\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e43\u0e19\u0e15\u0e32\u0e23\u0e32\u0e07\u0e19\u0e31\u0e49\u0e19 \u0e21\u0e35\u0e1a\u0e32\u0e07 field \u0e17\u0e35\u0e48\u0e16\u0e39\u0e01\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e43\u0e2b\u0e49\u0e21\u0e35\u0e04\u0e27\u0e32\u0e21\u0e2a\u0e33\u0e1e\u0e31\u0e19\u0e18\u0e4c\u0e01\u0e31\u0e1a\u0e15\u0e32\u0e23\u0e32\u0e07\u0e2d\u0e37\u0e48\u0e19\u0e43\u0e19\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e40\u0e14\u0e35\u0e22\u0e27\u0e01\u0e31\u0e19<br \/>\n\u0e2b\u0e23\u0e37\u0e2d\u0e2d\u0e35\u0e01\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e01\u0e47\u0e04\u0e37\u0e2d \u0e43\u0e19\u0e15\u0e32\u0e23\u0e32\u0e07\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e1e\u0e22\u0e32\u0e22\u0e32\u0e21\u0e08\u0e30\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e19\u0e31\u0e49\u0e19\u0e21\u0e35\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 Foreign key \u0e0b\u0e36\u0e48\u0e07\u0e40\u0e1b\u0e47\u0e19 Primary Key \u0e02\u0e2d\u0e07\u0e15\u0e32\u0e23\u0e32\u0e07\u0e2d\u0e37\u0e48\u0e19\u0e17\u0e35\u0e48\u0e2a\u0e31\u0e21\u0e1e\u0e31\u0e19\u0e18\u0e4c\u0e01\u0e31\u0e19\u0e2d\u0e22\u0e39\u0e48 \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e1b\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19\u0e02\u0e49\u0e2d\u0e1c\u0e34\u0e14\u0e1e\u0e25\u0e32\u0e14 \u0e23\u0e30\u0e1a\u0e1a\u0e08\u0e36\u0e07\u0e41\u0e08\u0e49\u0e07 error \u0e41\u0e25\u0e30\u0e44\u0e21\u0e48\u0e17\u0e33\u0e07\u0e32\u0e19\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 MySQL \u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e40\u0e02\u0e35\u0e22\u0e19\u0e44\u0e1b<br \/>\n<!--more--><\/p>\n<h4>\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49\u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19<\/h4>\n<ul>\n<li>\n\u0e01\u0e23\u0e13\u0e35\u0e43\u0e0a\u0e49 phpmyadmin \u0e14\u0e49\u0e27\u0e22\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 MySQL Query \u0e43\u0e2b\u0e49\u0e40\u0e2d\u0e32\u0e15\u0e34\u0e4a\u0e01\u0e16\u0e39\u0e01\u0e17\u0e35\u0e48 Enable foreign key checks \u0e2d\u0e2d\u0e01 \u0e2b\u0e23\u0e37\u0e2d\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 MySQL<\/p>\n<pre class=\"lang:default decode:true \" >SET FOREIGN_KEY_CHECKS=0;<\/pre>\n<p><\/br><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.codebee.co.th\/labs\/wp-content\/uploads\/2018\/11\/\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49-Error-Foreign-key-constraint-\u0e43\u0e19-MySQL-1.jpg\" alt=\"\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49-Error-Foreign-key-constraint-\u0e43\u0e19-MySQL-1\" \/><br \/>\n<\/br>\n<\/li>\n<li>\n\u0e01\u0e23\u0e13\u0e35\u0e43\u0e0a\u0e49 phpmyadmin \u0e41\u0e1a\u0e1a Import \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e01\u0e47\u0e43\u0e2b\u0e49\u0e40\u0e2d\u0e32\u0e15\u0e34\u0e4a\u0e01\u0e16\u0e39\u0e01\u0e2d\u0e2d\u0e01\u0e17\u0e35\u0e48 Enable foreign key checks<br \/>\n<\/br><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.codebee.co.th\/labs\/wp-content\/uploads\/2018\/11\/\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49-Error-Foreign-key-constraint-\u0e43\u0e19-MySQL-2.jpg\" alt=\"\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49-Error-Foreign-key-constraint-\u0e43\u0e19-MySQL-2\" \/><br \/>\n<\/br>\n<\/li>\n<\/ul>\n<p>\u0e16\u0e49\u0e32\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 <strong>FOREIGN_KEY_CHECKS = 0;<\/strong> \u0e41\u0e25\u0e49\u0e27\u0e22\u0e31\u0e07\u0e44\u0e21\u0e48\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16 create table \u0e2b\u0e23\u0e37\u0e2d insert \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e44\u0e14\u0e49\u0e43\u0e2b\u0e49\u0e25\u0e2d\u0e07\u0e22\u0e01\u0e40\u0e25\u0e34\u0e01 FOREIGN KEY \u0e14\u0e49\u0e27\u0e22\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e14\u0e49\u0e32\u0e19\u0e25\u0e48\u0e32\u0e07 <\/p>\n<pre class=\"lang:default decode:true \" >ALTER TABLE tablename DROP FOREIGN KEY fieldname;<\/pre>\n<p>\u0e16\u0e49\u0e32\u0e40\u0e1b\u0e47\u0e19\u0e01\u0e32\u0e23 import \u0e44\u0e1f\u0e25\u0e4c .sql \u0e40\u0e02\u0e49\u0e32\u0e21\u0e32\u0e43\u0e2b\u0e49\u0e40\u0e1b\u0e34\u0e14\u0e44\u0e1f\u0e25\u0e4c\u0e41\u0e25\u0e30\u0e25\u0e1a\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 add key \u0e17\u0e34\u0e49\u0e49\u0e07\u0e44\u0e1b\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14 \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e15\u0e32\u0e21\u0e14\u0e49\u0e32\u0e19\u0e25\u0e48\u0e32\u0e07\u0e04\u0e37\u0e2d\u0e25\u0e1a\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 ADD KEY `pet_uid` (`pet_uid`) \u0e2d\u0e2d\u0e01\u0e44\u0e1b<\/p>\n<pre class=\"lang:default decode:true \" >ALTER TABLE `expense`\r\n  ADD PRIMARY KEY (`expense_uid`),\r\n  ADD KEY `pet_uid` (`pet_uid`)<\/pre>\n<p>error \u0e19\u0e35\u0e49\u0e40\u0e01\u0e34\u0e14\u0e02\u0e36\u0e49\u0e19\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e1b\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19\u0e02\u0e49\u0e2d\u0e1c\u0e34\u0e14\u0e1e\u0e25\u0e32\u0e14\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e30\u0e2b\u0e27\u0e48\u0e32\u0e07\u0e15\u0e32\u0e23\u0e32\u0e07\u0e17\u0e35\u0e48\u0e2d\u0e32\u0e08\u0e08\u0e30\u0e44\u0e21\u0e48\u0e15\u0e23\u0e07\u0e01\u0e31\u0e19 \u0e40\u0e0a\u0e48\u0e19 \u0e01\u0e32\u0e23 insert \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e25\u0e07\u0e44\u0e1b\u0e43\u0e19 field \u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19 foreign key \u0e0b\u0e36\u0e48\u0e07\u0e40\u0e1b\u0e47\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e35\u0e48\u0e44\u0e21\u0e48\u0e21\u0e35\u0e2d\u0e22\u0e39\u0e48\u0e08\u0e23\u0e34\u0e07\u0e43\u0e19\u0e15\u0e32\u0e23\u0e32\u0e07\u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19 primary key \u0e23\u0e30\u0e1a\u0e1a\u0e08\u0e30\u0e41\u0e08\u0e49\u0e07 error \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e1b\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19\u0e44\u0e21\u0e48\u0e43\u0e2b\u0e49\u0e40\u0e01\u0e34\u0e14\u0e02\u0e49\u0e2d\u0e1c\u0e34\u0e14\u0e1e\u0e25\u0e32\u0e14\u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e19\u0e31\u0e48\u0e19\u0e40\u0e2d\u0e07\u0e04\u0e23\u0e31\u0e1a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint \u0e43\u0e19 MySQL \u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint is incorrectly formed \u0e27\u0e34\u0e18\u0e35\u0e41\u0e01\u0e49 Error Foreign key constraint&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4610,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"video","meta":{"footnotes":""},"categories":[2284,46],"tags":[1892,1891,1890,1677,1893],"class_list":["post-4603","post","type-post","status-publish","format-video","has-post-thumbnail","hentry","category--database","category-website-development-","tag-foreign-key","tag-foreign-key-constraint","tag-foreign-key-constraint-is-incorrectly-formed","tag-mysql","tag-primary-key","post_format-post-format-video"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/posts\/4603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/comments?post=4603"}],"version-history":[{"count":6,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/posts\/4603\/revisions"}],"predecessor-version":[{"id":4614,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/posts\/4603\/revisions\/4614"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/media\/4610"}],"wp:attachment":[{"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/media?parent=4603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/categories?post=4603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebee.co.th\/labs\/wp-json\/wp\/v2\/tags?post=4603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}