Syntax Error or Access Violation: 1071 Specified Key Was Too Long

Syntax Error or Access Violation: 1071 Specified Key Was Too Long

This error is created by the default character set used by Laravel in database. Anyone using MySQL version older than the 5.7.7 release or MariaDB older than the 10.2.2 release need to manually configure default string length generated by migrations in order for MySQL to create indexes for them.  This issue is clearly addressed in Laravel documentation.

SOLUTION 1
You need to add Schema::defaultStringLength in the boot function in your AppServiceProvider.

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

SOLUTION 2:
Enabling the innodb_large_prefix option in your database.

Note: After you solved this issue you may encounter base table or view already exists due to incomplete migration.

Comments are closed.