i got this problem while creating migration

247 Views Asked by At

I'm running 'php artisan migrate' I got this error:

([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))) after that In the AppServiceProvider.php

add this code

(use Illuminate\Support\Facades\Schema;and Schema::defaultStringLength(191);)

now I get another error

(PHP Fatal error: Cannot use Illuminate\Support\Facadesenter code here\Schema as Schema because the name is already in use in C:\xampp\htdocs\projects\app\Providers\AppServiceProvider.php on line 7)

the following are the AppServiceProvider.php code

<?php


namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use mysql_xdevapi\Schema;
use Illuminate\Support\Facades\Schema;

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()`enter code here`
    {
        //
    }
}
1

There are 1 best solutions below

3
On

I would imagine you're getting this error because you've tried to import 2 Schema classes.

Try removing use mysql_xdevapi\Schema; from the top of your AppServiceProvider.