PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes”)
While migration sometimes you face SQLSTATE[42000] error which says the specified key was too long.
You may face this error because you are running an older MySQL version, you may need to update your MySQL version to v5.7.7+.
As per the migration guide under Index Length MySQL/MariaDB,
You may also want to read Specific Table Migration in Laravel if ever need to migrate a specific table.
To figure out this error all you have to navigate to your Providers folder and open AppServiceProvide.php file.
SOLUTION: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
1 2 3 4 5 6 |
use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); } |
Use the Schema at the top of the file just before public class and write default string length inside the boot the function