Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis (ideagrams and smileys used in electronic messages and web pages). 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.

But for those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:

As outlined in the Migrations guide, to fix this all you have to do is edit the AppServiceProvider.php” file.

Step 1: Locate the file by browsing through the directory as thus app/Providers/AppServiceProvider.php

Step 2: Locate the boot method and set a default string length to any preferred value, but the value shouldn’t exceed 255 which is the maximum character value for varchar data type.

Below shows a sample code

use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(200);
}

After that everything should work perfectly.

Method 2, will be discussed in our next blog post.

First published in kodehauz

--

--