cklester's avatar

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

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!

0 likes
8 replies
wells's avatar
wells
Best Answer
Level 19

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.

28 likes
cklester's avatar

THANK YOU!

That resolved my issue.

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

wells's avatar

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

1 like
JunTheProgrammer's avatar

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 !

silverxjohn's avatar

@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.

jodyshop's avatar

Hi, I have faced such issue, when I double checked I found that I missed this:

use Schema;

So the use was the issue.

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Schema;

Please or to participate in this conversation.