Laravel - admin 安装 1071 Specified key was too long;  
                            
                                                    
                        
                    
                    
  
                    
                    环境配置说明:
windows10 + phpstudy8.1[Nginx1.15 + Mysql5.7 + PHP7.2]
选择的 laravel 7.*
网上有很多是 之前laravel5.4出现的问题,及相关解决方案。很多也指出是MySQL的问题,经过本人测试及查阅,最佳解决方案是
//解决办法:
use Illuminate\Support\Facades\Schema;
//设置默认字符串长度
Schema::defaultStringLength(191);

以下是出现的问题:
PS D:\WWW\lardy> php artisan admin:install
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
   Illuminate\Database\QueryException
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
  at D:\WWW\lardy\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675|
  1   D:\WWW\lardy\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:129
      Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
  2   D:\WWW\lardy\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:127
      PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
解决该问题的原文来自于:laravel进阶–1 Artisan 命令行
          
                    
                    
          
          
                关于 LearnKu
              
                    
                    
                    
 
推荐文章: