{"id":125,"date":"2017-04-08T23:14:08","date_gmt":"2017-04-08T20:14:08","guid":{"rendered":"http:\/\/antyat.ru\/?p=125"},"modified":"2017-04-08T23:14:08","modified_gmt":"2017-04-08T20:14:08","slug":"laravel-5-4-syntax-error-or-access-violation-1071-specified-key-was-too-long-max-key-length-is-767-bytes","status":"publish","type":"post","link":"http:\/\/antyat.ru\/?p=125","title":{"rendered":"Laravel 5.4 Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes"},"content":{"rendered":"<header class=\"post__header\">\n<h1 class=\"post__title\">Laravel 5.4: Specified key was too long error<\/h1>\n<\/header>\n<p>Laravel 5.4 made a change to the default database character set, and it\u2019s now <code>utf8mb4<\/code> which includes support for storing emojis. This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.<\/p>\n<p>For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:<\/p>\n<blockquote><p>[Illuminate\\Database\\QueryException]<br \/>\nSQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table <code>users<\/code> add unique <code>users_email_unique<\/code>(<code>email<\/code>))<\/p>\n<p>[PDOException]<br \/>\nSQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes<\/p><\/blockquote>\n<p>As outlined in the Migrations <a href=\"https:\/\/laravel.com\/docs\/master\/migrations#creating-indexes\">guide<\/a> to fix this all you have to do is edit your <code>AppServiceProvider.php<\/code> file and inside the <code>boot<\/code> method set a default string length:<\/p>\n<pre><code class=\"hljs css\"><span class=\"hljs-selector-tag\">use<\/span> <span class=\"hljs-selector-tag\">Illuminate<\/span>\\<span class=\"hljs-selector-tag\">Support<\/span>\\<span class=\"hljs-selector-tag\">Facades<\/span>\\<span class=\"hljs-selector-tag\">Schema<\/span>;\r\n\r\n<span class=\"hljs-selector-tag\">public<\/span> <span class=\"hljs-selector-tag\">function<\/span> <span class=\"hljs-selector-tag\">boot<\/span>()\r\n{\r\n    <span class=\"hljs-attribute\">Schema<\/span>::<span class=\"hljs-built_in\">defaultStringLength<\/span>(191);\r\n}\r\n<\/code><\/pre>\n<p>After that everything should work as normal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel 5.4: Specified key was too long error Laravel 5.4 made a change to the default database character set, and it\u2019s now utf8mb4 which includes support for storing emojis. This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything. For those running [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":1,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":126,"href":"http:\/\/antyat.ru\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions\/126"}],"wp:attachment":[{"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/antyat.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}