-1

When I was performing php artisan migrate on cmd in my laravel project. I'm getting the below error. Please help.enter image description here

Saengdaet
  • 1,516
  • 1
  • 14
  • 43
ShanWave007
  • 262
  • 1
  • 3
  • 15

4 Answers4

4
laravel 5.4.* file location : app/Providers/AppServiceProvider.php

AppServiceProvider.php It has been modified

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
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()
    {
        //
    }
}

After that execute the migrate Artisan command:

php artisan migrate
Mayur Panchal
  • 955
  • 5
  • 14
1

You might be running into the index length configuration.

The laravel documentation states the following

Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:

use Illuminate\Support\Facades\Schema;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191);
}
Raphael Cunha
  • 939
  • 5
  • 9
0

In AppServiceProvider.php which is located in (app/Providers) add this

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}
V. Alen
  • 88
  • 8
0

The error occurs because of the email is using unique() but it doesn't know how long is your unique value.. You have two ways to solve this

The first is set in global in your App\Providers\AppServiceProvider.php and then add your code in boot method:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

The second is only set in your migration table, you only need to specify the length of the string like:

$table->string('email', 191)->unique();
Saengdaet
  • 1,516
  • 1
  • 14
  • 43