Ever tried to run migrate and run into the Specified key was too long error.

Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing “emojis” in the database.

If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.3 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:

Laravel uses the utf8mb4 character set by default, which includes support for storing “emojis” in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
     Schema::defaultStringLength(191);
}

After that everything should work as normal.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *