{"id":129,"date":"2018-12-22T23:35:10","date_gmt":"2018-12-22T15:35:10","guid":{"rendered":"https:\/\/itrapt.com\/blog\/?p=129"},"modified":"2019-06-06T17:27:49","modified_gmt":"2019-06-06T09:27:49","slug":"cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails","status":"publish","type":"post","link":"https:\/\/itrapt.com\/blog\/cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails\/","title":{"rendered":"Cannot Add or Update a Child Row: A Foreign Key Constraint Fails"},"content":{"rendered":"<p>I encountered this error when I tried to add a new child row using CakePhp. Checking around forums and coding sites, there is always one suggestion whenever somebody asks this question &#8211; make sure that the foreign key exists in the parent table. I made sure that the key exists in the parent table, but it still keep giving ke the same error.<\/p>\n<p>I tried inserting the child row using phpMyAdmin.<\/p>\n<p>I tried inserting the row using an SQL INSERT statement.<\/p>\n<p>I tried editing a child row.<\/p>\n<p>All of them spewed the same error.<\/p>\n<p>After a few more hours of debugging, I had a lucky break. It turns out that I was using MyISAM as the table storage type rather than InnoDB. I changed the table and <i>voila<\/i>! I had no problem adding or editing child rows after that.<\/p>\n<p>I&#8217;ve been using MySQL\/MariaDB for years now, but I have barely scratched the surface.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I encountered this error when I tried to add a new child row using CakePhp. Checking around forums and coding sites, there is always one suggestion whenever somebody asks this question &#8211; make sure that the foreign key exists in the parent table. I made sure that the key exists in the parent table, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":""},"categories":[62],"tags":[64,63,58],"_links":{"self":[{"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/posts\/129"}],"collection":[{"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":2,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/posts\/129\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itrapt.com\/blog\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}