Press ESC to close

Manoj Bist

Laravel Syntax error or access violation – Specified key was too long

Laravel Syntax error or access violation



Syntax error or access violation:  Specified key was too long; 


Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis. This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.
For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:
Here is how to solve syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes error.

Open app/providers/EvenetServiceProvider.php
Now replace the code with the below-mentioned code.


namespace AppProviders;
use IlluminateSupportFacadesSchema;
use IlluminateSupportFacadesEvent;
use IlluminateFoundationSupportProvidersEventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'AppEventsEvent' => [
            'AppListenersEventListener',
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
  Schema::defaultStringLength(191);
        //
    }
} 


Look at this line


Schema::defaultStringLength(191);

defaultStringLength(191); 


you can adjust this number according to your database support.
That’s all
.
Thanks

Manoj Bist

A Passionate Web Developer/Designer With over 6 years of experience in the industry, Manoj Bist is a seasoned professional who combines technical expertise with a down-to-earth demeanor. As a lover of both technology and design, he thrives on creating seamless digital experiences that captivate and inspire.

Leave a Reply

Your email address will not be published. Required fields are marked *