When we migration of the table after the installation of the latest laravel at that time we face this type of error(1071 Specified key was too long; max key length is 767 bytes).
Because it’s not 520 bytes, but rather, 2080 bytes, which far exceeds 767 bytes, so we are facing this type of error.
Syntax error or access violation, #1071 – Specified key was too long; max key length is 767 bytes, PHP artisan migrate command error, long max key length is 767 bytes, syntax error or access violation 1071, MySQL error
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`)) at E:\xampp\htdocs\lara_auth\vendor\laravel\framework\src\Illuminate\Database\Connection.php:665 661| // If an exception occurs when attempting to run a query, we'll format the error 662| // message to include the bindings with SQL, which will make this exception a 663| // lot more helpful to the developer instead of just the database's errors. 664| catch (Exception $e) { > 665| throw new QueryException( 666| $query, $this->prepareBindings($bindings), $e 667| ); 668| } 669| Exception trace: 1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes") E:\xampp\htdocs\lara_auth\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459 2 PDOStatement::execute() E:\xampp\htdocs\lara_auth\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459 Please use the argument -v to see more details.
Now. let’s go we will solve the above error. first, open the AppServiceProvider.php file from the app/Providers/ directory. after then we will load the schema “use Illuminate\Support\Facades\Schema;” on the top header and set the “Schema::defaultStringLength(191);” into boot method.
You can see the below code, therefore, then you can better understand.
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { // } /** * Bootstrap any application services. * * @return void */ public function boot() { // Schema::defaultStringLength(191); } } ?>
After the above changes, you can again migrate the table and then it will be successfully migrated.
I have been surfing on-line greater than three hours today, but I never discovered any attention-grabbing article like yours. It’s beautiful worth enough for me. In my opinion, if all site owners and bloggers made just right content material as you did, the internet will probably be a lot more helpful than ever before. “No nation was ever ruined by trade.” by Benjamin Franklin.
Absolutely pent subject material, regards for information .
Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.