当前位置:首页 > 服务端 > 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

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`))
 
legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long _ JavaClub全栈架构师技术笔记

 

 

 

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); } 

 

legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long _ JavaClub全栈架构师技术笔记

<?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);
    }
}

 

这样做就成功解决问题:

legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long _ JavaClub全栈架构师技术笔记

 

 

 

作者:范仁义
来源链接:https://www.cnblogs.com/Renyi-Fan/p/14207460.html

版权声明:
1、Java侠(https://www.javaxia.com)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaxia.com/server/124794.html

标签: syntax error
分享给朋友:

“legend2v2---6、SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long” 的相关文章