简体   繁体   English

php artisan migrate:找不到类架构

[英]php artisan migrate: Class Schema not found

When doing a migration, in the Windows console I execute the command:进行迁移时,我在 Windows 控制台中执行以下命令:

php artisan migrate

When I run the command, it shows me the following error:当我运行命令时,它显示以下错误:

[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Market\Providers\Schema' not found

I would be very grateful if anyone can help me.如果有人能帮助我,我将不胜感激。

add following line on the top of that page (AppServiceProvider.php under providers directory)在该页面顶部添加以下行(Providers 目录下的 AppServiceProvider.php)

use Illuminate\Support\Facades\Schema;

or或者

use Schema;

It looks like you have fixed another problems with the message "Laravel 5.4: Specified key was too long error" using this article where you were recommended to add following code它看起来像你有固定与消息的另一个问题“Laravel 5.4:指定的键过长错误”使用这篇文章,你是建议添加以下代码

use Illuminate\Support\Facades\Schema;

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

to the file named到名为的文件

AppServiceProvider.php应用服务提供者.php

and you actually only changed the boot method and forget to update the use section.而您实际上只是更改了boot方法而忘记更新use部分。 Am I right?我对吗?

The Article says:文章说:

Laravel 5.4 made a change to the default database character set, and it's now utf8mb4 which includes support for storing emojis. Laravel 5.4 对默认数据库字符集进行了更改,现在是 utf8mb4,其中包括对存储表情符号的支持。 This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.这只会影响新应用程序,只要您运行 MySQL v5.7.7 及更高版本,您就不需要做任何事情。

For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:对于那些运行 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

It seems your migration code is in a namespace and that's where PHP is looking for Schema class.您的迁移代码似乎位于命名空间中,而这正是 PHP 寻找Schema类的地方。 Add the following at the top of your file:在文件顶部添加以下内容:

use Schema;

or refer to the Schema class using fully qualified namespace:或使用完全限定的命名空间引用Schema类:

\Schema::table(...);

After adding to your AppServiceProvider.php file添加到您的 AppServiceProvider.php 文件后

use Illuminate\Support\Facades\Schema;

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

Don't forget to run别忘了奔跑

php artisan migrate:fresh

I kept facing the same issue because i hadn't migrated fresh (ie drop tables and create new ones)我一直面临同样的问题,因为我没有迁移新的(即删除表并创建新表)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM