4

In Connection.php line 647:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table users add uni que users_email_unique(email))

In Connection.php line 449:

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

How can i solve this??

When i want to migrate default migrations in CMD this error happens.

D-Shih
  • 44,943
  • 6
  • 31
  • 51
heisenberg
  • 73
  • 7
  • 4
    Possible duplicate of [Laravel migration: unique key is too long, even if specified](https://stackoverflow.com/questions/23786359/laravel-migration-unique-key-is-too-long-even-if-specified) – Ilya Yaremchuk Jan 31 '18 at 09:07
  • Set a shorter key length? You've set your email field to a really long value? Can you post the table structure? – G_V Jan 31 '18 at 09:27
  • well this is because mySQL indexes are only available for string that has length lower than 192 .. you may want to change the defaultStringLength .. – Demonyowh Jan 31 '18 at 10:03

2 Answers2

4

Add this to your AppServiceProvider.php file:

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

This article by Laravel News explains it

Prince Lionel N'zi
  • 2,510
  • 2
  • 12
  • 27
2

For Laravel 5.4 add code in AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

and in boot

public function boot()
{
    Schema::defaultStringLength(191);
}
Ilya Yaremchuk
  • 2,007
  • 2
  • 19
  • 36