欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Laravel 5.4因特殊字段太長導(dǎo)致migrations報錯的解決

 更新時間:2017年10月22日 08:36:44   作者:隨風(fēng)  
這篇文章主要給大家介紹了關(guān)于Laravel 5.4因特殊字段太長導(dǎo)致migrations報錯的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起看看吧。

前言

本文主要介紹了關(guān)于Laravel 5.4因特殊字段太長導(dǎo)致migrations報錯的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面話不多說了,來一起看看詳細(xì)的介紹:

laravel 5.4 改變了默認(rèn)的數(shù)據(jù)庫字符集,現(xiàn)在utf8mb4包括存儲emojis支持。MySQL 需要v5.7.7或者更高版本,當(dāng)你試著在一些MariaDB或者一些老版本的的MySQL上運行 migrations 命令時,你會碰到下面這個錯誤:

 [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

解決方法

經(jīng)過查詢,我們可以在 AppServiceProvider.php 文件里的 boot 方法里設(shè)置一個默認(rèn)值:

<?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()
 {
  //
 }
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,本文還有許多不足,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論