CodeBriefly
Tech Magazine

How to Fix Laravel Syntax Error or Access Violation 1071

0 1,827

Get real time updates directly on you device, subscribe now.

In this article, we will discuss the most common issue “How to Fix Laravel Syntax Error or Access Violation 1071”.  When we start a new project within Laravel then we face this.

An exception is thrown because Laravel 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:

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

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

You can fix this error using the following solution.

Update the AppServiceProvider.php located at app/providers.

use Illuminate\Support\Facades\Schema;

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

After, updating the AppServiceProvider.php. The migrate command executed without any issue.

Conclusion

In this article, I’m trying to explain to you the How you can fix the Laravel Syntax Error or Access Violation 1071. Hope you like this article. Please feel free to add the comment if any query or you can submit your feedback 🙂


You may like

If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee

Get real time updates directly on you device, subscribe now.

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More