{"id":3052,"date":"2025-04-16T17:35:43","date_gmt":"2025-04-16T17:35:43","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=3052"},"modified":"2025-04-16T17:35:45","modified_gmt":"2025-04-16T17:35:45","slug":"fixing-laravel-migration-error-unknown-collation-utf8mb4_0900_ai_ci","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/fixing-laravel-migration-error-unknown-collation-utf8mb4_0900_ai_ci\/","title":{"rendered":"Fixing Laravel Migration Error: &#8220;Unknown Collation: utf8mb4_0900_ai_ci&#8221;"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"141\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6-1024x141.png\" alt=\"\" class=\"wp-image-3053\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6-1024x141.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6-300x41.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6-768x106.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6-1536x211.png 1536w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/04\/image-6.png 1825w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>While working with Laravel and MySQL, you might run into an error during migrations like this one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Illuminate\\Database\\QueryException\nSQLSTATE&#91;HY000]: General error: 1273 Unknown collation: 'utf8mb4_0900_ai_ci'\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Why This Happens<\/h2>\n\n\n\n<p>The collation <code>utf8mb4_0900_ai_ci<\/code> is introduced in <strong>MySQL 8.0<\/strong>. If you&#8217;re using an older version of MySQL (like 5.7 or earlier), it doesn&#8217;t recognize this collation, and Laravel throws this error during migrations or queries.<\/p>\n\n\n\n<p>Laravel 10+ and Laravel 11 use this collation by default in their database config, assuming the database supports it.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Fix It<\/h2>\n\n\n\n<p>There are two common ways to fix this issue:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udee0 Option 1: Downgrade the Collation in <code>config\/database.php<\/code><\/h3>\n\n\n\n<p>Open the <code>config\/database.php<\/code> file in your Laravel project.<\/p>\n\n\n\n<p>Locate the <code>mysql<\/code> connection settings and change the collation and charset like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'mysql' => &#91;\n    'driver' => 'mysql',\n    'host' => env('DB_HOST', '127.0.0.1'),\n    'port' => env('DB_PORT', '3306'),\n    'database' => env('DB_DATABASE', 'your_db_name'),\n    'username' => env('DB_USERNAME', 'root'),\n    'password' => env('DB_PASSWORD', ''),\n    'charset' => 'utf8mb4',\n    'collation' => 'utf8mb4_unicode_ci', \/\/ Change this line\n    ...\n],\n<\/code><\/pre>\n\n\n\n<p>Then, <strong>clear the config cache<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan config:clear\n<\/code><\/pre>\n\n\n\n<p>Now try running the migration again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Option 2: Upgrade Your MySQL Server<\/h3>\n\n\n\n<p>If possible, upgrade your MySQL server to <strong>version 8.0 or higher<\/strong>, which fully supports <code>utf8mb4_0900_ai_ci<\/code>.<\/p>\n\n\n\n<p>This is ideal for production servers or when you need access to newer MySQL features.<\/p>\n\n\n\n<p>This is a common issue when developing Laravel apps locally on XAMPP, WAMP, or older MySQL versions. Fortunately, a simple config change is usually all you need to get back on track.<\/p>\n\n\n\n<p><strong>Pro Tip:<\/strong> Always make sure your development and production environments use compatible database versions and configurations to avoid such surprises.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While working with Laravel and MySQL, you might run into an error during migrations like this one: Why This Happens The collation utf8mb4_0900_ai_ci is introduced in MySQL&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3052","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3052"}],"version-history":[{"count":2,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3052\/revisions"}],"predecessor-version":[{"id":3055,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3052\/revisions\/3055"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}