user image

Jo Micheal
Published in : 2022-01-20

[solved] SQLSTATE[42000]: Syntax error or access violation

Laravel

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') )

I get this error when i try to run the migration using 

php artisan migrate

what should I do to figure out this Error?

web-brackets.com

Comments

Joseph Morgan Date : 2022-01-20

Best answers

11

Best answers

11

that's because the defaultStringLength is not setup, you need to limit it from /app/Providers/AppServiceProvider.php
using the Schema 

so the file should looks like 

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register(){
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(){
        //
        Schema::defaultStringLength(191);
    }
}

I imported the schema using use Illuminate\Support\Facades\Schema;
then added Schema::defaultStringLength(191); into the boot function
Let me know if this worked with you

Jo Micheal Date : 2022-01-20

Thanks, this was the issue, when i updated the file like this it worked fine 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Laravel error 419 page expired
Publish date: 2021-04-10 | Comments: 2
How to get original attribute value in Laravel?
Publish date: 2022-02-23 | Comments: 3
Laravel redirect to the last location after login
Publish date: 2022-02-21 | Comments: 1
How can i pass data from blade template to vue component?
Publish date: 2022-02-11 | Comments: 1
tymon/jwt-auth 0.5.12 requires illuminate/support ~5.0
Publish date: 2022-02-18 | Comments: 2
Uncaught Error: Missing required parameters: sitekey Laravel
Publish date: 2022-01-08 | Comments: 2