Home  >  Article  >  PHP Framework  >  laravel database migration error

laravel database migration error

步履不停
步履不停Original
2019-06-27 16:57:482735browse

laravel database migration error

Problem Description

(1) Laravel 5.4 or later has changed the default database character set, and now utf8mb4 includes support for storing emojis. If you are running MySQL v5.7.7 or higher, you don't need to do anything.
(2) When you try to run the migrations command on some MariaDB or some older versions of MySQL, you may encounter the following error:
Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
[The specified key is too long, the maximum key length is 767 bytes, because the default string length of laravel is 767 bytes, so you have to configure it manually. 】

Solution

<?php
namespace App\Providers;
// 导入Schema类
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // 在app/providers/AppServiceProvider.php中boot方法中加上 
        Schema::defaultStringLength(191);
    }
}

For more Laravel related technical articles, please visit the Laravel Tutorial column to learn!

The above is the detailed content of laravel database migration error. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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