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
The recommended solution is to enable
innodb_large_prefix
option of MySQL so you won't be getting into subsequent problems. And here is how to do that:Open the
my.ini
MySQL configuration file and add the below lines under the[mysqld]
line like this.After that, save your changes and restart your MySQL service.
Rollback if you need to and then re-run your migration.
Just in case your problem still persists, go to your database configuration file and set
'engine' => null,
to'engine' => 'innodb row_format=dynamic'
Hope it helps!
The approached that work here was pass a second param with the key name (a short one):
I am adding two sollution that work for me.
1st sollution is:
Edit
'engine' => null,
to'engine' => 'InnoDB',
This worked for me.
2nd sollution is:
Open database.php file insde config dir/folder.
2.Edit
'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci',
to
'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',
Goodluck
This issue is caused in Laravel 5.4 by the database version.
According to the docs (in the
Index Lengths & MySQL / MariaDB
section):In other words, in
<ROOT>/app/Providers/AppServiceProvider.php
:But as the comment on the other answer says:
So the documentation also proposes another solution:
For anyone else who might run into this, my issue was that I was making a column of type
string
and trying to make it->unsigned()
when I meant for it to be an integer.For someone who don't want to change
AppServiceProvider.php
. (In my opinion, it's bad idea to changeAppServiceProvider.php
just for migration)You can add back the data length to the migration file under
database/migrations/
as below:create_users_table.php
create_password_resets_table.php