4
votes

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?

1
Did you create a new service provider and put the above code in that, or did you put the above code in the AppServiceProvider class? Either way, can you please post the entire code for the file and identify it, that may help us help you resolve the issue.stratedge
my code is in AppServiceProvider class and my entire code is...,,,<?php namespace App\Providers; use Illuminate\Support\Facades\Schema; class AppServiceProvider extends ServiceProvider { public function boot() { Schema::defaultStringLength(191); } public function register() { } }Tavash
Does your AppServiceProvider class still have the use Illuminate\Support\ServiceProvider; statement in it?stratedge
No, i changed that to this code "use Illuminate\Support\Facades\Schema;"Tavash
Don't replace any thing just add new thing that is in article. So keep as previouse code also.Niklesh Raut

1 Answers

8
votes

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()
    {
        //
    }
}