Home > Database > Mysql Tutorial > Laravel Migration Error: How to Fix 'Specified Key Was Too Long'?

Laravel Migration Error: How to Fix 'Specified Key Was Too Long'?

DDD
Release: 2024-12-09 08:26:06
Original
268 people have browsed it

Laravel Migration Error: How to Fix

Laravel Migration Error: "Syntax Error or Access Violation: 1071 Specified Key Was Too Long" Resolved

Upon encountering the aforementioned migration error in Laravel 5.4, it's essential to address the underlying cause. This error arises when a specified key exceeds the maximum character length allowed for an index.

To resolve this issue, as suggested in the Laravel 7.x documentation, modify your /app/Providers/AppServiceProvider.php file as follows:

use Illuminate\Support\Facades\Schema;

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

By setting the defaultStringLength to 191, you ensure that all future migrations adhere to this length limit.

Alternatively, you can enable the innodb_large_prefix option in your database configuration. However, it's important to consult your database's documentation for specific instructions on how to enable this option.

The above is the detailed content of Laravel Migration Error: How to Fix 'Specified Key Was Too Long'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template