{"id":439,"date":"2018-01-25T13:40:06","date_gmt":"2018-01-25T13:40:06","guid":{"rendered":"https:\/\/mellowhost.com\/blog\/?p=439"},"modified":"2018-01-25T13:40:06","modified_gmt":"2018-01-25T13:40:06","slug":"programming-laravel-error-specified-key-was-too-long","status":"publish","type":"post","link":"https:\/\/mellowhost.com\/blog\/programming-laravel-error-specified-key-was-too-long.html","title":{"rendered":"Programming: Laravel Error &#8211; Specified Key Was Too Long"},"content":{"rendered":"<p>A common error I have seen users reporting using Laravel, is the following:<\/p>\n<p><code>SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes<\/code><\/p>\n<p>The error actually happens because Laravel 5.5 assumes you have MySQL 5.7.7 or above. While on MySQL 5.7.7 the key size was increased than the older versions.<\/p>\n<h4>How to fix laravel Specified key was too long<\/h4>\n<p>To fix this, find the\u00a0AppServiceProvider.php file under app\/Providers folder, and add the following line before start of the class:<\/p>\n<p><code>use Illuminate\\Support\\Facades\\Schema;<\/code><\/p>\n<p>Then, inside the boot() method under the class, add the following line:<\/p>\n<p><code>Schema::defaultStringLength(191);<\/code><\/p>\n<p>If you restart your laravel migration or the query, it should work fine now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A common error I have seen users reporting using Laravel, is the following: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes The error actually happens because Laravel 5.5 assumes you have MySQL 5.7.7 or above. While on MySQL 5.7.7 the key size was increased than &hellip; <a href=\"https:\/\/mellowhost.com\/blog\/programming-laravel-error-specified-key-was-too-long.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Programming: Laravel Error &#8211; Specified Key Was Too Long&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[272,273,271],"tags":[274,275,276],"_links":{"self":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/439"}],"collection":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/comments?post=439"}],"version-history":[{"count":1,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/posts\/439\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mellowhost.com\/blog\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}