Laravel installation wizard

  Wed 20 / 12 / 2023

  Posted by: Markie Mags

Category : Laravel

Tags : laravel , deployment

Description

i recieve that error on the last part of laravel installation wizard how wil i resolve the issue?


SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table password_resets add primary key (email))


View Code
                        SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table password_resets add primary key (email))
                
  Answered by CDL

This error typically occurs when you are using a version of MySQL older than 5.7.7 or MariaDB older than 10.2.2. The issue is related to the default string length used for indexing in Laravel migrations.


Solution:

Change Default String Length in Laravel


Add the following code to your AppServiceProvider class in the boot method:

Also make sure to add this Schema namespace at the top:

use Illuminate\Support\Facades\Schema;

php
Schema::defaultStringLength(191);

This code sets the default string length for the Laravel schema builder to 191, which is the maximum length allowed for index keys in MySQL and MariaDB.

  Comment   Share
0 Likes   1 Comment


comment-author
Hadayat Niazi Super Admin

If the above problem was solved, please mark this post as solved.



Reply


commented 9 months ago