0

I'm using xampp as server in my laravel project. While creating migrations, I'm facing an error: only one migration table can be created; others are not being created.

This is the error:

**Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
   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`))
  at C:\xampp\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664

    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just
the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e    666|             );
    667|         }
    668|
  Exception trace:
  1   PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
      C:\xampp\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
  2   PDOStatement::execute()
      C:\xampp\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458**
Andrew Fan
  • 1,313
  • 5
  • 17
  • 29
  • Possible duplicate of [Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes](https://stackoverflow.com/questions/42244541/laravel-migration-error-syntax-error-or-access-violation-1071-specified-key-wa) – Burgi Jun 10 '19 at 13:18

2 Answers2

1

Update your database.php file in the config folder as show below

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

to

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',

and it should work. If it doesn't work then update AppServiceProvider.php in app/Providers/ as shown below.

use Illuminate\Support\Facades\Schema; //Import Schema

function boot()
{
    Schema::defaultStringLength(191); //Solved by increasing StringLength
}
Rafay Hassan
  • 740
  • 8
  • 23
0

You can try this:

AppServiceProvider.php

use Illuminate\Support\Facades\Schema; //Import Schema

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

Hope that helps.