[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
<?php $table->string('email', 300);
Method 1: Specify Smaller Value
The easiest fix for this issue is to just update the columns and specify the value of the particular field to 255 characters.
<?php $table->string('email', 255);
Method 2: Update config/database.php Configuration
The next fix is to update the "configuration database" which is located in the "config" folder.
config/database.php
<?php 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',
Method 3: Update defaultStringLength value
The 3rd method is to update the defaultStringLength to have a value of 191 and this should fix the error.
<?php Schema::defaultStringLength(191); Schema::create('users', function (Blueprint $table) { // your columns definition });
Leave a reply