Home > PHP Framework > Laravel > body text

laravel database migration error

步履不停
Release: 2019-06-27 17:57:04
Original
2695 people have browsed it

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);
    }
}
Copy after login

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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!