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.

3
  • 4
    Possible duplicate of Laravel migration: unique key is too long, even if specified Commented Jan 31, 2018 at 9:07
  • Set a shorter key length? You've set your email field to a really long value? Can you post the table structure? Commented Jan 31, 2018 at 9: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 .. Commented Jan 31, 2018 at 10:03

2 Answers 2

4

Add this to your AppServiceProvider.php file:

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

This article by Laravel News explains it

Sign up to request clarification or add additional context in comments.

Comments

2

For Laravel 5.4 add code in AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

and in boot

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.