进行迁移时,我在Windows控制台中执行以下命令:
php artisan migrate
当我运行该命令时,会出现以下错误提示:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Market\Providers\Schema' not found
如果有人能帮助我,我将非常感激。
进行迁移时,我在Windows控制台中执行以下命令:
php artisan migrate
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Market\Providers\Schema' not found
如果有人能帮助我,我将非常感激。
use Illuminate\Support\Facades\Schema;
或者
use Schema;
看起来您已经通过这篇文章解决了"Laravel 5.4: Specified key was too long error"的另一个问题,其中建议您添加以下代码。
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
关于文件名:
AppServiceProvider.php
你只改了boot
方法,却忘记更新use
部分了。我说的对吗?
这篇文章指出:
Laravel 5.4 默认数据库字符集已更改为 utf8mb4,支持存储表情符号。这仅影响新应用程序,只要您运行的 MySQL 版本高于 v5.7.7,您就不需要做任何事情。
对于运行 MariaDB 或旧版本 MySQL 的用户,在尝试运行迁移时可能会遇到以下错误:
[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))
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071
Specified key was too long; max key length is 767 bytes
看起来你的迁移代码在一个命名空间中,这就是PHP寻找Schema类的地方。请在文件顶部添加以下内容:
use Schema;
或者使用完全限定的命名空间引用 Schema 类:
\Schema::table(...);
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
别忘了运行
php artisan migrate:fresh
我一直遇到同样的问题,因为我没有进行新的迁移(即删除表并创建新表)
AppServiceProvider.php
文件位于app/Providers/AppServiceProvider.php
,以便为人们澄清和使其易于理解。 - user5683940