gpt4 book ai didi

php - 流明 : How to fix the SQLSTATE[42000]: Syntax error or access violation: 1071 on laravel lumen

转载 作者:行者123 更新时间:2023-12-05 05:11:53 25 4
gpt4 key购买 nike

我使用 lumen 框架启动了一个 PHP 项目。

当我尝试从控制台执行命令 php artisan migrate:fresh 时,出现以下错误

SQLSTATE[42000]: Syntax error or access violation: 1071

这是 Laravel 中的一个众所周知的错误,但这个问题不是重复的,因为 lumen 上没有启动方法,如 documentation说:

Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider.

但是,当我尝试在微框架 Lumen 中使用此修复程序时,错误仍然存​​在。

最佳答案

这个错误主要是因为你没有在boot()函数中设置defaultStringLength

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071

解决方案:

只需在 app/Providers/AppServiceProvider.php 方法中添加以下代码:

use Illuminate\Support\Facades\Schema;

public function boot()
{
Schema::defaultStringLength(191);
}

关于php - 流明 : How to fix the SQLSTATE[42000]: Syntax error or access violation: 1071 on laravel lumen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54991202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com