解決在laravel中auth建立時(shí)候遇到的問題
當(dāng)你使用auth做用戶登錄注冊(cè)的時(shí)候,會(huì)很方便,但是你在做數(shù)據(jù)庫遷移的時(shí)候可能會(huì)遇到一個(gè)問題
$ php artisan migrate Migration table created successfully. [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes (SQL: alter table `users` add unique ` users_email_unique`(`email`)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes
不要慌,這里說的是你的數(shù)據(jù)庫遷移完成了,蛋疼的是這里有一個(gè)報(bào)錯(cuò),會(huì)使你在接下來項(xiàng)目中后面的遷移操作繼續(xù)報(bào)錯(cuò)。
[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table `users` (`id` int unsigned not null auto_incr ement primary key, `name` varchar(191) not null, `email` varchar(191) not n ull, `password` varchar(191) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci) [PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists
解決方案如下:
索引長(zhǎng)度 & MySQL / MariaDB#
Laravel 默認(rèn)使用 utf8mb4 字符,包括支持在數(shù)據(jù)庫存儲(chǔ)「表情」。如果你正在運(yùn)行的 MySQL release 版本低于5.7.7 或 MariaDB release 版本低于10.2.2 ,為了MySQL為它們創(chuàng)建索引,你可能需要手動(dòng)配置遷移生成的默認(rèn)字符串長(zhǎng)度,你可以通過調(diào)用
項(xiàng)目/app/Providers/AppServiceProvider.php 中的 Schema::defaultStringLength 方法來配置它:
use Illuminate\Support\Facades\Schema; /** * 引導(dǎo)任何應(yīng)用程序服務(wù)。 * * @return void */ public function boot() { Schema::defaultStringLength(191); }
或者你可以為數(shù)據(jù)庫開啟 innodb_large_prefix 選項(xiàng),有關(guān)如何正確開啟此選項(xiàng)的說明請(qǐng)查閱數(shù)據(jù)庫文檔。
以上這篇解決在laravel中auth建立時(shí)候遇到的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
yii2中dropDownList實(shí)現(xiàn)二級(jí)和三級(jí)聯(lián)動(dòng)寫法
本篇文章主要介紹了yii2中dropDownList實(shí)現(xiàn)二級(jí)和三級(jí)聯(lián)動(dòng)寫法 ,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-04-04PHP 超高性能可擴(kuò)展HTTP服務(wù)框架Webman
本文主要介紹了超高性能可擴(kuò)展HTTP服務(wù)框架Webman,webman用于替代傳統(tǒng)的php-fpm架構(gòu),提供超高性能可擴(kuò)展的HTTP服務(wù),感興趣的可以了解一下2024-02-02Yii2實(shí)現(xiàn)自定義獨(dú)立驗(yàn)證器的方法
這篇文章主要介紹了Yii2實(shí)現(xiàn)自定義獨(dú)立驗(yàn)證器的方法,結(jié)合實(shí)例形式分析了Yii2自定義獨(dú)立驗(yàn)證器的實(shí)現(xiàn)與使用方法,需要的朋友可以參考下2017-05-05php解析url并得到url中的參數(shù)及獲取url參數(shù)的四種方式
本文給大家介紹php解析url并得到url中的參數(shù)及獲取url參數(shù)的四種方式,涉及到將字符串參數(shù)變?yōu)閿?shù)組,將參數(shù)變?yōu)樽址南嚓P(guān)知識(shí),本文代碼簡(jiǎn)單易懂,感興趣的朋友一起看看吧2015-10-10ThinkPHP模板判斷輸出Empty標(biāo)簽用法詳解
這篇文章主要介紹了ThinkPHP模板判斷輸出Empty標(biāo)簽用法,需要的朋友可以參考下2014-06-06一張表搞清楚php is_null、empty、isset的區(qū)別
這篇文章主要介紹了一張表搞清楚php is_null、empty、isset的區(qū)別,isset 判斷變量是否已存在,empty 判斷變量是否為空或?yàn)?,is_null 判斷變量是否為NULL,需要的朋友可以參考下2015-07-07