'php artisan migrate' Error:Class 'App\Providers\Schema' not found

Published 7 months ago by cklester

I'm running 'php artisan migrate' after having made an adjustment to accommodate the fix suggested here (https://laravel-news.com/laravel-5-4-key-too-long-error). The exact error is this:

[Symfony\Component\Debug\Exception\FatalThrowableError] Class 'App\Providers\Schema' not found

Please let me know what else I need to do to get this migration working.

Thank you!

Best Answer (As Selected By cklester)
wells

In the AppServiceProvider.php, you did not include the necessary use statement at the top of the file.

use Illuminate\Support\Facades\Schema;

That defines the namespace path to the Schema class so you can simply call Schema::defaultStringLength(191); in the boot method.

wells
wells
7 months ago (91,295 XP)

In the AppServiceProvider.php, you did not include the necessary use statement at the top of the file.

use Illuminate\Support\Facades\Schema;

That defines the namespace path to the Schema class so you can simply call Schema::defaultStringLength(191); in the boot method.

cklester

THANK YOU!

That resolved my issue.

I'm sure with more experience, I would have known already to do that, yes? :D

wells
wells
7 months ago (91,295 XP)

Absolutely. It'll become second nature as you get more familiar with namespaces, use statements, and such. All the best.

JunTheProgrammer

I'm a beginner, but I must say.. shouldn't this be configured by default? I wouldn't say that this is a big issue, considering that it would take just 2 minutes (or less) to set this up for any new project.

Could someone shed light on this?

Also, thank you, @wells !

carevaloq87

Thanks @wells , that worked for me too!

silverxjohn

@JunTheProgrammer Laravel is a framework where you build different things.

Namespaces is a PHP thing.

Laravel doesn't know which facades/classes you'll ever use. So it isn't 'pre-configured' by default. Not everyone uses Schema on a ServiceProvider for instance.

A workaround for this is to use an IDE like PHPStorm. It automatically adds the namespace as you type the class name.

Sign In or create a forum account to participate in this discussion.