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

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

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

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

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