0
votes

I am new in Laravel. I am facing a problem to migrate my users and password reset table.

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

I have tried so many solution like (AppServiceProvider, database collation change, changing migration file ) but none of them give me a solution.

AppServiceProvider.php

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
}

Database.php

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
    ],
1
What is your problem ? does it showing errors ? upload your error here. - Md.Sukel Ali
Type your error please - Mohammad Hosseini
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: a lter table users add unique users_email_unique(email)) - sifat shaharear
When I give the command user table add with my database but collation shows utf8mb4_unicode_ci but I changed my database.php - sifat shaharear
Show your migration table for user and password reset. - Lim Kean Phang

1 Answers

0
votes


After setting defaultStringLength in AppServiceProvider maybe re-run your project with php artisan serve solve your problem.