Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rafaelmsantos's avatar

Laravel 5.4 failing on php artisan migrate after php artisan make:auth

Hi, I decided to test the new Laravel 5.4. So I started with the basic commands:

$ laravel new blog

$ php artisan make:auth

$ php artisan migrate

The last command returns an error, I will write it here:

[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`))   
[PDOException]                                                                               
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key  
   length is 767 bytes  

The database configuration on .env file is correct, since booth migrations and users table are created.

Any idea why is this failing?

0 likes
23 replies
jannndo's avatar

I'm using MySQL v5.7.9, so its higher than v5.7.7 but it still doesn't work. Although restraining the string lenght through laravel is working, it still bugs me. Anybody any idea whats wrong? thanks

1 like
Tpojka's avatar

I solved it successfylly followed this advice.

2 likes
nanpaul68's avatar
Level 2

to fix this, all you have to do is to edit your AppServiceProvider.php file and add to the boot method a default string length

use Illuminate\Support\Facades\Schema;

function boot()
{
    Schema::defaultStringLength(191);
}
54 likes
AsifAmeer's avatar

None of these methods are working. There must be some workable solution added here please. :(

1 like
msechrest's avatar

I have fixed this issue by using the suggested answer but it is still bugging me.

I am using mysql 5.7.11 and according to the documentation I should not have to do anything to make this work. Anyone have any idea why it is not working by default?

1 like
Gonzalo2683's avatar

Hello, I have made the suggested changes, but when I run the command artisan migrate again, only the migrations table was generated, the rest of the tables do not generate them. What could be the problem?

deselbi's avatar

this also can solve it:

in config/databa se.php in mysql section

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

replace with

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

https://gist.github.com/deselbi/75e35c472351ada436c4077e0a03e7f2

this will allow user email to be longer then 191 characters log but will not support some charactes:

http://stackoverflow.com/questions/30074492/what-is-the-difference-between-utf8mb4-and-utf8-charsets-in-mysql

9 likes
cyntechtic's avatar

Your AppServiceProvider.php file should look thus

antoniocusro's avatar

Had the same issue with ClearDb on Heroku. The recommended solution solved the issue.

Thank you @nanpaul68 . It worked and it saved me lots of hours of frustration.

digitalagua's avatar

In case you were banging you head against the wall like I was.

I had this issue with migrations when I was adding unique to a string with a length.

        $table->string('name', 255);
        $table->unique('name');

I removed the length value and it worked.

        $table->string('name');
        $table->unique('name');
matthewinSpire's avatar

I have tried all of the suggested answers and I'm still getting the same error. I also just updated XAMPP in the hopes that would fix the issue, but to no avail. Any other suggestions?

Cronix's avatar

@matthewinSpire Do you actually need to use the utf8mb4 character set with emoji support? If not you can just use utf8 in your db config.

Cronix's avatar

@matthewinSpire Yes, but you'd probably also need to recreate the database using the same charset/collation settings, too. Use innodb too.

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

Please or to participate in this conversation.