I just started to learn Laravel 5.4 and trying to migrate a users table in Laravel. When I run my migration I get this error:
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
After following this tutorial, I now have another error:
PHP Fatal error: Class 'App\Providers\ServiceProvider' not found
My migration code is
use Illuminate\Support\Facades\Schema;
public function boot()
{
//
Schema::defaultStringLength(191);
}
What am I doing wrong?
The problem is that you are missing the use statement that identifies where the ServiceProvider class is. Since the AppServiceProvider class extends ServiceProvider, but there is no use statement, PHP assumes that the class can be found in the same namespace as AppServiceProvider. This is why it can't find \App\Providers\ServiceProvider - because \App\Providers is the namespace of the AppServiceProvider class.
Try this
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With