Home Backend Development PHP Tutorial How to solve the problem of migration error caused by special fields being too long in Laravel5.4 framework

How to solve the problem of migration error caused by special fields being too long in Laravel5.4 framework

Oct 24, 2017 am 09:07 AM
laravel5.4 Field

Preface

This article mainly introduces the relevant content about migration errors caused by Laravel 5.4 due to too long special fields. It is shared for everyone’s reference and study. I won’t say much below. Let’s take a look at the detailed introduction:

laravel 5.4 changed the default database character set, and now utf8mb4 includes support for storing emojis. MySQL requires v5.7.7 or higher. When you try to run the migrations command on some MariaDB or some older versions of MySQL, 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
Copy after login

Solution

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


<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
//添加的代码
use Illuminate\Support\Facades\Schema;
 
class AppServiceProvider extends ServiceProvider
{
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
  //添加的代码
  Schema::defaultStringLength(191);
 }
 
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
  //
 }
}
Copy after login

The above is the detailed content of How to solve the problem of migration error caused by special fields being too long in Laravel5.4 framework. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to determine if a field is empty in PHP? How to determine if a field is empty in PHP? Mar 20, 2024 pm 03:09 PM

PHP is a scripting language widely used in website development. For developers, it is often necessary to determine whether a field is empty. In PHP, determining whether a field is empty can be achieved through some simple methods. This article will introduce how to determine whether a field is empty in PHP, and provide specific code examples for your reference. In PHP, you can usually use the empty() function or isset() function to determine whether a field is empty. Next, we introduce the usage of these two functions respectively. Use the empty() function

NoSuchFieldError in Java - Solution to field not found NoSuchFieldError in Java - Solution to field not found Jun 25, 2023 am 11:33 AM

NoSuchFieldError in Java - Solution to field not found Java is a high-level programming language that is widely used in enterprise-level applications and large-scale data processing. During the development process of Java, errors such as NoSuchFieldError may occur. This error means that the JVM cannot find the required field at runtime. In this article, we will take a deeper look at NoSuchFieldError and how to resolve it. What is NoSuchFieldE

What does mysql field mean? What does mysql field mean? Jul 10, 2023 pm 02:14 PM

A mysql field is a column of a specific type and length in a mysql database table that is used to store data. In MySQL, each field must have a specific data type. Common data types include integers, floating point numbers, strings, dates, and times. These data types determine the data that MySQL can store in each field.

How to add fields to the database table How to add fields to the database table Mar 18, 2021 pm 02:13 PM

Methods to add fields in the table: 1. Use the "ALTER TABLE table name ADD new field name data type;" statement to add fields at the end; 2. Use the "ALTER TABLE table name ADD new field name data type FIRST;" statement to add it at the beginning Field; 3. Use the "ALTER TABLE table name ADD new field name data type [constraints] AFTER existing field name;" statement to add a field in the middle.

How to add fields in dedecms How to add fields in dedecms Feb 17, 2023 am 10:50 AM

How to add fields to dedecms: 1. Enter the dedecms backend and find the "Common Article Model" in "Core-Channel Model"; 2. Click "Field Management" to enter the field management interface and click Add New Field; 3. Add a new field In the field interface, just fill in the form prompt text, field name and other information in sequence.

How to use Vue form processing to hide and display elements of form fields How to use Vue form processing to hide and display elements of form fields Aug 10, 2023 pm 07:51 PM

How to use Vue form processing to hide and display elements of form fields Introduction: In front-end development, processing forms is a common and important task. Sometimes we need to hide and display form field elements based on user selection or other conditions. It is very simple to implement this function in Vue. This article will introduce how to use Vue form processing to hide and display elements of form fields, and attach code examples for reference. 1. Use the v-if instruction to hide and display the v-if instruction in Vue according to

How to determine if a field is not empty in php How to determine if a field is not empty in php Feb 21, 2023 am 09:18 AM

PHP method to determine whether a field is not empty: 1. Use the isset method to determine whether the variable has been initialized; 2. Use the empty method to detect whether the variable is "empty"; 3. Use the "var == null" method to determine whether the variable is "empty" ; 4. Use the is_null method to detect whether the variable is "null"; 5. Use the "var === null" method to detect whether the variable is "null", and the type of the variable must also be "null".

ChatGPT wrote the plug-in in five minutes. It has perfect functions and can also add requirements to correct bugs. ChatGPT wrote the plug-in in five minutes. It has perfect functions and can also add requirements to correct bugs. Apr 11, 2023 pm 03:52 PM

What is the level of writing code for ChatGPT? In less than 5 minutes, I made a WordPress (a content management system software) plug-in, and the code was very clean. The tester's name is David Gewirtz, a veteran who entered the IT industry in 1982. He has worked for companies including: Symantec, Apple, and Pyramid Technology. Even with 40 years of experience in the industry, he couldn't help but sigh after seeing ChatGPT's capabilities: He thought there wouldn't be too many surprises, but he was surprised. In the review article, he also said that it was all fascinating, surprising, and scary at the same time. So, how exactly did he do the test? Let’s take a look together. No energy

See all articles