This issue is caused in Laravel 5.4 by the database version.
According to the docs (in the Index Lengths & MySQL / MariaDB
section):
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 theSchema::defaultStringLength
method within yourAppServiceProvider
.
In other words, in <ROOT>/app/Providers/AppServiceProvider.php
:
// Import Schema
use Illuminate\Support\Facades\Schema;
// ...
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Add the following line
Schema::defaultStringLength(191);
}
// ...
}
But as the comment on the other answer says:
Be careful about this solution. If you index email fields for example, stored emails can only have a max length of 191 chars. This is less than the official RFC states.
So the documentation also proposes another solution:
Alternatively, you may enable the
innodb_large_prefix
option for your database. Refer to your database's documentation for instructions on how to properly enable this option.