zoukankan      html  css  js  c++  java
  • 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);
        }
    }

    这样做就成功解决问题:

     
  • 相关阅读:
    [LeetCode] 1160. Find Words That Can Be Formed by Characters
    [LeetCode] 561. Array Partition I
    [LeetCode] 942. DI String Match
    [LeetCode] 852. Peak Index in a Mountain Array
    [LeetCode] 461. Hamming Distance
    [LeetCode] 617. Merge Two Binary Trees
    SSM项目实现连接两个mysql数据库
    springboot导入excel到mysql
    Mysql修改表备注, 列信息
    sql.xml where ids in的写法
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/14207460.html
Copyright © 2011-2022 走看看