Skip to content

Instantly share code, notes, and snippets.

@fabinou
Created January 4, 2020 13:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabinou/5294ae21ac462659eb9e9f7de6b75d91 to your computer and use it in GitHub Desktop.
Save fabinou/5294ae21ac462659eb9e9f7de6b75d91 to your computer and use it in GitHub Desktop.
Laravel, fix pour SQLSTATE[42000]: Syntax error or access violation: 1071 La clé est trop longue. Longueur maximale: 1000"
Ajouter à app/Providers/AppServiceProvider.php :
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
@dricislam
Copy link

ca marche !

@julien-sibille
Copy link

In case it does not suits your needs, let's add 'engine' => 'InnoDB', to config/database.php (mysql array)

@Souyette
Copy link

Souyette commented Nov 25, 2022

it doesn't work for me i mean the Schema::defaultStringLength(191);
It's written : Class "App\Providers\Schema" not found
Does anyone has an answer ?
(i'm french btw)

@Souyette
Copy link

Souyette commented Nov 25, 2022

@MiRa23ch
Copy link

after adding this ligne ' Schema::defaultStringLength(191); ' we need to import "Schema"
so w add this 'use Illuminate\Support\Facades\Schema; '
after this ligne ' use Illuminate\Support\ServiceProvider; '

@GreyShellzone
Copy link

Cette méthode n'a pas marché pour moi, et a même généré une erreur supplémentaire.
J'ai installé la version 10 de Laravel et voici ce qui a marché :

Allez dans le fichier config/database.php

Modifiez :

  1. 'charset' => 'utf8mb4', en 'charset' => 'utf8',
  2. 'collation' => 'utf8mb4_unicode_ci', en 'collation' => 'utf8_unicode_ci',

J'espère avoir aidé quelqu'un. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment