Laravel – Specified key was too long Error

By Dillon Smart · · · 0 Comments

With Laravel 5.4, some users may be hit with the Laravel Specified key was too long Error when migrating the database. This is because in the latest Laravel update, the developers made changes to the default database charset, making it utf8mb4.

If your using MySQL 5.7.7 or higher, you won’t encounter this issue, however older versions of MySQL or MariaDB will have this problem.

You can find the solution to this error in the Laravel Documentation. You will need to make a change to the AppServiceProvider.php file, located in app/Providers/AppServiceProvider.php.

Solving Laravel Specified key was too long

Step One:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; // This line needs to be added

Step Two: 

public function boot()
{
    Schema::defaultStringLength(191); // This line needs to be added
}

Now, you should be able to run your migration as normal. For more development tutorials, check out our Web Development category.

LaravelPHP

0 Comment

Was this helpful? Leave a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to use Microsoft Graph API with Laravel

Updated 1st January 2024

Microsoft Graph is a gateway to data and intelligence within Microsoft 365. Microsoft Graph is great to build apps for organizations and consumers using the vast amount of data stored in Microsoft 365. In this post, we are going to integrate with Microsoft Graph API in Laravel to get all users assigned to your tenant.

Find php.ini on Apple Silicon installed with Homebrew

Updated 1st October 2023

Are you having trouble finding your php.ini file which was installed locally with Homebrew? Packages installed with Homebrew can be installed in different locations making it hard to find, especially if you are on new Apple Mac running Apple’s Silicon chips. Here, I will show you home to locate your locally installed php.ini file installed

Create a custom WordPress taxonomy for posts and pages

Updated 16th August 2022

Sometimes when building a website using WordPress, the standard taxonomies Categories and Tags just aren’t enough, and you need to create more. Let’s learn how to create our own custom WordPress taxonomy. WordPress has made creating your own taxonomy easy, and you can even add your custom taxonomies to pages too. To accomplish this we