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

    这样做就成功解决问题:

     
  • 相关阅读:
    4 stackstorm定时器基础 Sky
    3 stackstorm rule Sky
    2 stackstrom action Sky
    1 StackStorm介绍 Sky
    stackstorm安装 Sky
    stackstorm webui安装 Sky
    3.8 Go之并发和并行
    3.2 Go之语言竞争状态
    3.2 Go之语言并发通信
    图床_typora设置.md
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/14207460.html
Copyright © 2020-2023  润新知