Laravel: How to fix the MySQL related "Specified key was too long error" error in Laravel
This is a common problem (especially if you use a local development environment such as XAMPP).
The error will look something like this:
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Luckily the fix is simple. Add the following to the boot() method of your app/Providers/AppServiceProvider.php file:
- Schema::defaultStringLength(191);
More...
Comments and discussion about How to fix the MySQL related "Specified key was too long error" error in Laravel
Found this interesting? Maybe you want to read some more in this series?
Or see other topics in the Laravel language
Blade Templating System
Controllers
Laravel Database Stuff
Eloquent
Routes and Routing
General Laravel Stuff
Laravel Collections
Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScriptOr see random questions
How to force non www in htaccess
How to return JSON data to the user in Laravel?
How to show (or log) all SQL queries executed by Laravel
What is the difference between ( for ... in ) and ( for ... of ) in javascript?
How to set the Expires header in .htaccess
How to output (echo/print) content in PHP
How to round a number in JS?
How to check if an object or variable is an array, in JS?
How to convert a string to an array of it's characters in PHP?
How to add comments in PHP