Laravel 5.4 and MariaDB Errors
Laravel, MariaDB, Migrations
When running migrations on Laravel 5.4 and MariaDB you may encounter this error:
[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
Solution
Amend the AppServiceProvider
- which you’ll find here: app/Providers/AppServiceProvider.php
. Use Illuminate\Support\Facades\Schema
to set a default string length which can be used in migrations. The ameded class might look like this:
Migrate the Database
You may end up with a part-migration error, whereby tables have been created during a broken migration, but the migrations
table is missing. Here’s an example showing the database after receiving the above-quoted error:
With the database in this state, you won’t be able to roll back migrations.
To fix, delete the tables manually at the MariaDB prompt:
After manually amending the database, close the MariaDB CLI by typing \q
.
At this point you should be able to run the migration successfully:
comments powered by Disqus