Migration error on Laravel 5.4 with php artisan make:auth
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e
users
add uniqueusers_email_unique
([PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
As already specified we add to the AppServiceProvider.php in App/Providers
you can see more details in the link bellow (search for "Index Lengths & MySQL / MariaDB") https://laravel.com/docs/5.5/migrations
BUT WELL THAT's not what I published all about! the thing is even when doing the above you will likely to get another error (that's when you run
php artisan migrate
command and because of the problem of the length, the operation will likely stuck in the middle. solution is below, and the user table is likely created without the rest or not totally correctly) we need to roll back. the default roll back will not work. because the operation of migration didn't like finish. you need to delete the new created tables in the database manually.we can do it using tinker as in below:
I myself had a problem with users table.
after that you're good to go
php artisan migrate:rollback
php artisan migrate
For me what worked was to update the dependencies by running.
You should also install the latest mysql version.
In the
AppServiceProvider.php
,you include this code top of the file.And you add this code in boot method.
I'm just adding this answer here as it's the
quickest
solution for me. Just set the default database engine to'InnoDB'
on/config/database.php
then run
php artisan config:cache
to clear and refresh the configuration cacheI have just modified following line in
users
andpassword_resets
migration file.Old :
$table->string('email')->unique();
New :
$table->string('email', 128)->unique();
Voila!!
The issue solved by the following way.
Add the following code in AppServiceProvider.php
The code block