In this tutorial we will see how we can solve laravel migration error like database setting is not correct error 1071 specified key was too long max key length is 767 bytes.
When we are going to migrate then its show key was too long in laravel. So if you want to solve this issue then follow below step. Every laravel beginner developer face a problem like Syntax error or access violation: 1071 Specified key was too long max k when they are going to migrate thier project database.
Now We will see hot we can solve database setting is not correct error 1071 specified key was too long max key length is 767 bytes error from our project.
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tableusers
add uniqueusers_email_unique
(
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php
file and inside the boot
method set a default string length:
app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
After that everything should work as normal.
#laravel #migration-error #error #syntax-error