MattB
4 months ago
742
7
Laravel

Syntax error with new Laravel projects

Posted 4 months ago by MattB

I don't know if this is something I'm doing wrong or everyone who creates a new Laravel (version 5 or 6, doesn't seem to matter) project has to fix each time.

Whenever I create a new project and try to run an initial migration, I get this error:

Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")

I can fix it just fine, but seems I have to do it every time. Is there something I should be doing when I create the project? Tried to reinstall Laravel on my PC but it didn't help. Tried creating a project using these commands, but no difference:

laravel new blog

composer create-project --prefer-dist laravel/laravel blog "6.*" (or "5.*")

I have to fix it by adding the following to appServiceProvider:

use Illuminate\Support\Facades\Schema; //NEW: Import Schema

function boot()
{
    Schema::defaultStringLength(191); //NEW: Increase StringLength
}

Please sign in or create an account to participate in this conversation.