【发布时间】:2020-03-22 18:23:10
【问题描述】:
我正在尝试将表迁移到数据库。我正在学习有关 Laravel 的课程,但出现错误。
C:\laragon\www\blog
λ php artisan migrate
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 76
7 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
at C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
2 PDOStatement::execute()
C:\laragon\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:459
Please use the argument -v to see more details.
C:\laragon\www\blog
λ
我在 PHPMyAdmin 中创建了一个数据库,当我执行迁移时,它从 4 个表中迁移了 2 个表,这意味着它们在 .env 文件上正确连接。我尝试通过 PHPMyAdmin 手动添加这些表,但之后当我制作工厂文件和播种机时出现不同的错误,所以我被困在了这个问题上。
在那之前我跑了:
λ php artisan make:migration create_todos_table
Created Migration: 2019_11_27_081314_create_todos_table
一切正常,但迁移时出现错误。谢谢
【问题讨论】:
-
你知道这个问题缺少什么吗? 3 个重复的答案...哦等等
-
@lagbox 删除了我的答案!
-
@NitishKumar 我只是在开玩笑 :) 实际上,这里已经有很多类似的重复问题了
-
我之前尝试过这个解决方案,但我得到了另一个错误,Symfony\Component\Debug\Exception\FatalThrowableError