• 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 IlluminateSupportFacadesSchema;  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`))
     

    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 IlluminateSupportFacadesSchema;  public function boot() {     Schema::defaultStringLength(191); } 

    <?php
    
    namespace AppProviders;
    
    use IlluminateSupportServiceProvider;
    use IlluminateSupportFacadesSchema;
    
    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);
        }
    }

    这样做就成功解决问题:

     
  • 相关阅读:
    冗余链接-684-并查集
    Chrome浏览器进程
    BFC布局规则
    Front-end 前端优化总结
    Flex弹性布局
    Browse兼容性问题
    组合关系与组合模式
    YUI3组件框架之plugin
    javascript数据类型及转换
    矩阵打印
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/14207460.html
Copyright © 2020-2023  润新知