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
If you want to change in AppServiceProvider then you need to define the length of email field in migration. just replace the first line of code to the second line.
create_users_table
create_password_resets_table
After successfully changes you can run the migration.
Note: first you have to delete (if you have) users table, password_resets table from the database and delete users and password_resets entries from migration table.
This is common since Laravel 5.4 changed the default database charater set to utf8mb4. What you have to do, is: edit your App\Providers.php by putting this code before the class declaration
Also, add this to the 'boot' function
Schema::defaultStringLength(191);
Schema::defaultStringLength(191);
will define the length of all strings 191 by default which may ruin your database. You must not go this way.Just define the length of any specific column in the database migration class. For example, I'm defining the "name", "username" and "email" in the
CreateUsersTable
class as below:update & insert these lines in app/Providers/AppServiceProvider.php
set your database engine in config/database.php in 'mysql' array
Instead of setting a limit on length I would propose the following, which has worked for me.
Inside
replace this line for mysql
upon
I have solved this issue and edited my config->database.php file to like my database ('charset'=>'utf8') and the ('collation'=>'utf8_general_ci'), so my problem is solved the code as follow: