{"id":72,"date":"2012-03-12T01:24:25","date_gmt":"2012-03-12T06:24:25","guid":{"rendered":"http:\/\/en.latindevelopers.com\/ivancp\/?p=72"},"modified":"2012-03-12T01:24:25","modified_gmt":"2012-03-12T06:24:25","slug":"mysql-must-improve-error-messages","status":"publish","type":"post","link":"http:\/\/en.latindevelopers.com\/ivancp\/2012\/mysql-must-improve-error-messages\/","title":{"rendered":"MySQL must improve error messages"},"content":{"rendered":"<p>I just finished a database modification, a new foreign key creation\u00a0 shouldn&#8217;t be take more than 5 mins, but I spent 2 hours because MySQL still have some useless error messages.<\/p>\n<p>There is a way to create a new foreign key:<\/p>\n<pre lang=\"sql\">-- Create two tables foo and bar\r\ncreate table foo (\r\n\tid integer not null primary key,\r\n\tbar_id int not null    -- foreign key\r\n);\r\ncreate table bar (\r\n\tid integer not null primary key\r\n);\r\n-- Try to create a foreign key on `foo`\r\nalter table foo\r\n\tadd foreign key(bar_id) references bar(SOME_FIELD) ;<\/pre>\n<p>The last sentence returns a generic error message:<\/p>\n<p><code>Error Code: 1005. Can't create table 'temp.#sql-4bd7_11' (errno: 150)<\/code><\/p>\n<p>Everything would have been easier if I had noticed that wrong field name <code>bar(SOME_FIELD)<\/code>, sometimes happens,\u00a0 but if MySQL would have shown a different message like <code>\"field bar.SOME_FIELD don't exists\"<\/code> I would not be awake until 2 am.<\/p>\n<p>I&#8217;m using MySQL 5.5.21 community edition.<\/p>\n<p>if I had noticed that wrong field name<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-official sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/mysql-must-improve-error-messages\/\" data-text=\"MySQL must improve error messages\"  >Tweet<\/a><\/li><li class=\"share-facebook\"><div class=\"fb-share-button\" data-href=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/mysql-must-improve-error-messages\/\" data-layout=\"button_count\"><\/div><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>I just finished a database modification, a new foreign key creation\u00a0 shouldn&#8217;t be take more than 5 mins, but I spent 2 hours because MySQL still have some useless error messages. There is a way to create a new foreign key: &#8212; Create two tables foo and bar create table foo ( id integer not [&hellip;]<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-official sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/mysql-must-improve-error-messages\/\" data-text=\"MySQL must improve error messages\"  >Tweet<\/a><\/li><li class=\"share-facebook\"><div class=\"fb-share-button\" data-href=\"http:\/\/en.latindevelopers.com\/ivancp\/2012\/mysql-must-improve-error-messages\/\" data-layout=\"button_count\"><\/div><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":21,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[18,5],"jetpack_featured_media_url":"http:\/\/en.latindevelopers.com\/ivancp\/wp-content\/uploads\/2012\/02\/logo-mysql-170x115.png","jetpack_shortlink":"https:\/\/wp.me\/p2f09V-1a","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/72"}],"collection":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":2,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":74,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/posts\/72\/revisions\/74"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/media\/21"}],"wp:attachment":[{"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/en.latindevelopers.com\/ivancp\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}