Laravel 5.4 solves the error caused by too long special fields in migrations. laravelmigrations

Source: Internet
Author: User

Laravel 5.4 solves the error caused by too long special fields in migrations. laravelmigrations

Preface

This article mainly introduces the information about the migrations error reported by Laravel 5.4 due to the long special field. We will share the content for your reference. I will not talk much about it below. Let's take a look at the detailed introduction:

Laravel 5.4 has changed the default database character set. Now utf8mb4 includes support for storing emojis. MySQL requires v5.7.7 or later. When you try to run the migrations command on MariaDB or some old MySQL versions, you will encounter the following error:

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

Solution

After query, we can set a default value in the boot method in the AppServiceProvider. php file:

<? Phpnamespace App \ Providers; use Illuminate \ Support \ ServiceProvider; // added code use Illuminate \ Support \ Facades \ Schema; class AppServiceProvider extends ServiceProvider {/*** Bootstrap any application services. ** @ return void */public function boot () {// added code Schema: defaultStringLength (191);}/*** Register any application services. ** @ return void */public function register (){//}}

Summary

The above is all the content of this article. There are still many shortcomings in this article. I hope this article will have some reference and learning value for everyone's learning or work. If you have any questions, please leave a message, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.