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

laravel - admin安装 intall会报错  Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

以下是出现的问题:

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 命令行

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

这个是 Laravel 5.4 时候的问题,参见

3年前 评论
张惠众 (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!