Have you ever get SQLSTATE 42000 error in PHP, Yes of course this error occurs several time when you’re using PDO connection in PHP. And in this article i’m going to cover why this error occurs in Laravel and how to solve in this error in laravel framework.
Why this error occurs in Laravel?
In Laravel 5.4 and above the default database character set is changed to
utf8mb4 which supports for the storing of Emojis. This error occurs on MySQL version less than 5.7.7 and MariaDB version less than 10.1 and higher you do not need to do anything.
SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table
SQLSTATE: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
How to solve SQLSTATE 42000 error in Laravel
To solve this error, locate
app/Providers/AppServiceProvider.php and add
boot method as following.
public function boot()
Once you have added now you’re good go. Now just run
php artisan migrate your error will be solved.
If problem persist again just leave a comment in comment box. I’m happy to guide you.