legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long
legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long
一、总结
一句话总结:
you need to place this code in your 【AppServiceProvider.php】:use Illuminate\Support\Facades\Schema; public function boot() { 【Schema::defaultStringLength(191);】 }
二、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long
1、问题
运行
php artisan migrate
出现
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add u
nique `users_email_unique`(`email`))
php artisan migrate
出现
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add u
nique `users_email_unique`(`email`))

2、解答及代码
网上有很多很多资料,比如可以参照下列博客:
https://www.cnblogs.com/linzenews/p/12764939.html
https://blog.csdn.net/sqlquan/article/details/81153777
https://blog.csdn.net/sinat_33801009/article/details/80817486
等等等等
If you are using MariaDB or an older version of MySQL, you need to place this code in your AppServiceProvider.php:
use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
<?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); } }
这样做就成功解决问题:
版权申明:欢迎转载,但请注明出处
一些博文中有一些参考内容因时间久远找不到来源了没有注明,如果侵权请联系我删除。
在校每年国奖、每年专业第一,加拿大留学,先后工作于华东师范大学和香港教育大学。
2025-04-30:宅加太忙,特此在网上找女朋友,坐标上海,非诚勿扰,vx:fan404006308
AI交流资料群:753014672