6

When doing a migration, in the Windows console I execute the command:

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.

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
FranMoronR
  • 61
  • 1
  • 1
  • 2

4 Answers4

30

add following line on the top of that page (AppServiceProvider.php under providers directory)

use Illuminate\Support\Facades\Schema;

or

use Schema;
Sabyasachi Ghosh
  • 1,402
  • 14
  • 18
  • 2
    To be more precise the `AppServiceProvider.php` file is located in `app/Providers/AppServiceProvider.php` just to clarify and make it easy for people –  Apr 16 '19 at 15:38
12

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

use Illuminate\Support\Facades\Schema;

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

to the file named

AppServiceProvider.php

and you actually only changed the boot method and forget to update the use section. 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. 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.

For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:

[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
Rajbir Shienh
  • 2,965
  • 1
  • 14
  • 21
Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191
4

It seems your migration code is in a namespace and that's where PHP is looking for Schema class. Add the following at the top of your file:

use Schema;

or refer to the Schema class using fully qualified namespace:

\Schema::table(...);
jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
0

After adding to your AppServiceProvider.php file

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)

Godana Emiru
  • 48
  • 1
  • 9