Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running default migrations #17714

Closed
evandojunior opened this issue Feb 1, 2017 · 4 comments
Closed

Error while running default migrations #17714

evandojunior opened this issue Feb 1, 2017 · 4 comments

Comments

@evandojunior
Copy link

  • Laravel Version: 5.4.*
  • PHP Version: 7.0.14
  • Database Driver & Version:
    MySQL 5.5.42

Description:

When you run the php artisan migrate command, the following error occurs:

[Illuminate\Database\QueryException]                                             
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too l  
  ong; max key length is 767 bytes (SQL: alter table `users` add unique `users_em  
  ail_unique`(`email`)) 
[PDOException]                                                                   
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too l  
  ong; max key length is 767 bytes                                                 
                                  

Steps To Reproduce:

$ php artisan migrate
@RikSomers
Copy link

RikSomers commented Feb 1, 2017

This has been reported several times:
#17530 #17508 #17337

It's also documented in the Migrations documentation: https://laravel.com/docs/5.4/migrations#indexes ( under Index Lengths & MySQL / MariaDB)

Adding this in your boot method of the AppServiceProvider should do the trick:

Schema::defaultStringLength(191);

like so:

use Illuminate\Support\Facades\Schema;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191);
}

@evandojunior
Copy link
Author

@RikSomers It worked, thank you!

@vinayakkulkarni
Copy link

sweet thanks @RikSomers

@RikSomers
Copy link

No problem, we're here to help eachother :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants