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); }
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!