CYIMANA Faisal
CYIMANA Faisal

Reputation: 13

Migration error during creation of table in laravel

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**

Upvotes: 0

Views: 517

Answers (2)

Maitri Patel
Maitri Patel

Reputation: 46

You can try this:

AppServiceProvider.php

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

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

Hope that helps.

Upvotes: 0

Rafay Hassan
Rafay Hassan

Reputation: 770

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
}

Upvotes: 1

Related Questions