Home  >  Article  >  PHP Framework  >  What should I do if an error occurs in the Larabel migration file?

What should I do if an error occurs in the Larabel migration file?

藏色散人
藏色散人forward
2021-11-29 14:54:351768browse

The tutorial column of Laravel below will introduce to you the solution to the SQLSTATE[42000] error when migrating files in Larabel. I hope it will be helpful to everyone!

What should I do if an error occurs in the Larabel migration file?

The solution to an error reported when Laravel executes the php artisan migrate command

Illuminate\Database\QueryException  : 
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; 
max key length is 1000 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

Solution

Modify app/ Add the following content to the Providers/AppServiceProvider.php file:

<?php

namespace App\Providers;use Illuminate\Support\ServiceProvider;use Illuminate\Support\Facades\Schema;class AppServiceProvider extends ServiceProvider{
    public function register()
    {
    }

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

Modify part

Schema::defaultStringLength(191);
Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of What should I do if an error occurs in the Larabel migration file?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete