php - 默认 create_users_table 抛出最大密钥长度错误
问题描述
我通过在命令提示符窗口中执行这些代码行来启动我的 Laravel 项目。
cd C:\xampp\htdocs
composer global require laravel/installer
laravel new iezon
然后我执行了构建身份验证方案的命令,我还没有编辑任何东西。
artisan make:auth
然后我转到我的配置文件夹,在里面database.php
,我用覆盖它的文件mysql
同样将其更改为正确的信息。.env
现在,我创建迁移表来检查我与数据库的连接,方法是:
php artisan migrate:install
并安装我的表(默认用户表):
php artisan migrate:fresh
然后在此调试中引发错误:
Dropped all tables successfully.
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 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
at C:\xampp\htdocs\iezon\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
C:\xampp\htdocs\iezon\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
2 PDOStatement::execute()
C:\xampp\htdocs\iezon\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
任何想法我错过了什么命令或做错了什么?除了具有正确信息的database.php
文件和文件之外,我没有更改任何文件内容。我怎样才能解决这个问题?.env
mysql
解决方案
Go To AppServiceProvider.php in ```app\Providers```
并boot()
通过添加此行进行更改
\Schema::defaultStringLength(191);
function boot()
{
\Schema::defaultStringLength(191);
}
Laravelutf8mb4
默认使用字符集,其中包括支持在数据库中存储“表情符号”。如果您运行的 MySQL 版本早于该5.7.7
版本或 MariaDB 版本早于该10.2.2
版本,您可能需要手动配置迁移生成的默认字符串长度,以便 MySQL 为它们创建索引。您可以通过Schema::defaultStringLength
在您的AppServiceProvider
推荐阅读
- sql-server - 创建不允许删除特定列中的值的触发器?
- python - 使用 Kivy 访问类变量
- javascript - 从 Font Awesome 导入许多图标
- python-3.x - UPDATE 数组在 python 上执行很多
- c++ - 修改 const std::vector 的元素
通过 const_cast - r - 如何通过聚合 R 中的二进制项来创建新变量?
- tensorflow - 如何使用 FFT 和神经网络对声音进行分类?我应该使用 CNN 还是 RNN?
- ruby-on-rails - Rspec突然只运行一项测试
- sql-server - 如何将数据从多个表插入到 SSIS 中的单个表中?
- java - 有没有办法在点的末尾添加一个字符串而不手动输入它?