當(dāng)你使用auth做用戶登錄注冊的時候,會很方便,但是你在做數(shù)據(jù)庫遷移的時候可能會遇到一個問題
$ 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ù)庫遷移完成了,蛋疼的是這里有一個報錯,會使你在接下來項(xiàng)目中后面的遷移操作繼續(xù)報錯。
[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
解決方案如下:
索引長度 MySQL / MariaDB#
Laravel 默認(rèn)使用 utf8mb4 字符,包括支持在數(shù)據(jù)庫存儲「表情」。如果你正在運(yùn)行的 MySQL release 版本低于5.7.7 或 MariaDB release 版本低于10.2.2 ,為了MySQL為它們創(chuàng)建索引,你可能需要手動配置遷移生成的默認(rèn)字符串長度,你可以通過調(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)的說明請查閱數(shù)據(jù)庫文檔。
以上這篇解決在laravel中auth建立時候遇到的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- 解決Laravel5.2 Auth認(rèn)證退出失效的問題
- 解決laravel5中auth用戶登錄其他頁面獲取不到登錄信息的問題
- Laravel的Auth驗(yàn)證Token驗(yàn)證使用自定義Redis的例子
- laravel實(shí)現(xiàn)Auth認(rèn)證,登錄、注冊后的頁面回跳方法
- Laravel 自帶的Auth驗(yàn)證登錄方法
- laravel 使用auth編寫登錄的方法
- Laravel框架Auth用戶認(rèn)證操作實(shí)例分析