Skip to content

Instantly share code, notes, and snippets.

@dheysonalves
Created January 25, 2021 16:03
Show Gist options
  • Select an option

  • Save dheysonalves/07943bc83b7cb50f17eab75d4d43108c to your computer and use it in GitHub Desktop.

Select an option

Save dheysonalves/07943bc83b7cb50f17eab75d4d43108c to your computer and use it in GitHub Desktop.

Revisions

  1. dheysonalves revised this gist Jan 25, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion error.md
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,6 @@ Para solucionar, deve ser editado o arquivo de boot dos serviços do laravel, de
    {
    Schema::defaultStringLength(191);
    }
    ```
    ```

    Onde é determinado o tamanho padrão dos tipos string do banco de dados.
  2. dheysonalves created this gist Jan 25, 2021.
    26 changes: 26 additions & 0 deletions error.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # Laravel Error - Specified key was too long error

    ## Problema

    Quando rodando versões antigas do Maria ou do MySql - antes da versão 5.7.7 -, o erro é disparado no console do Laravel na tentativa de popular o banco com migration.

    ```php
    [Illuminate\Database\QueryException]
    SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

    [PDOException]
    SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
    ```

    ## Solução

    Para solucionar, deve ser editado o arquivo de boot dos serviços do laravel, dentro da pasta provider, *AppServiceProvider.php*, na função *boot()*.

    ```php
    use Illuminate\Support\Facades\Schema;

    public function boot()
    {
    Schema::defaultStringLength(191);
    }
    ```