gpt4 book ai didi

我修复了错误的 Laravel 迁移 : Class 'App\Providers\ServiceProvider' not found, 后的 PHP fatal error : unique key is too long,

转载 作者:行者123 更新时间:2023-12-03 20:17:50 26 4
gpt4 key购买 nike

我刚开始学习 Laravel 5.4 并尝试在 Laravel 中迁移用户表。当我运行迁移时,出现此错误:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes



关注后 this tutorial ,我现在有另一个错误:

PHP Fatal error: Class 'App\Providers\ServiceProvider' not found



我的迁移代码是
use Illuminate\Support\Facades\Schema;

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

我究竟做错了什么?

最佳答案

问题是您缺少 use标识 ServiceProvider 位置的语句类是。自 AppServiceProvider类扩展 ServiceProvider ,但没有 use声明,PHP 假定该类可以在与 AppServiceProvider 相同的命名空间中找到。 .这就是它找不到 \App\Providers\ServiceProvider 的原因- 因为 \App\ProvidersAppServiceProvider 的命名空间类(class)。

尝试这个

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

关于我修复了错误的 Laravel 迁移 : Class 'App\Providers\ServiceProvider' not found, 后的 PHP fatal error : unique key is too long,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45775231/

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