2017-04-13 48 views
2

[Illuminate \ Database \ QueryException] SQLSTATE [42000]:語法錯誤或訪問衝突:1071指定密鑰太長;最大密鑰長度爲767個字節(SQL:改變TABLê用戶添加獨特users_email_unique(電子郵件))Laravel遷移錯誤:語法錯誤或訪問衝突:1071指定的鍵太長;最大密鑰長度爲767字節laravel 5.3

[PDOException] SQLSTATE [42000]:語法錯誤或訪問衝突:1071 指定的鍵過長;最大密鑰長度是767字節

最新錯了?即時通訊使用laravel 5.3

回答

3

指的Laravel NewsLaravel's migration guide

正如遷移概述指南來解決這一切,你需要做的就是編輯AppServiceProvider.php文件和引導方法內部設置一個默認的字符串長度:

use Illuminate\Support\Facades\Schema; 

function boot() 
{ 
    Schema::defaultStringLength(191); 
} 
+0

不工作...這項工作在拉拉維爾5.4 我嘗試laravel 5.3我得到同樣的錯誤 –

0

這錯誤來自basically..If您嘗試通過phpMyAdmin來增加列的長度的數據庫,你會得到同樣的錯誤。

0

正如遷移概述指導來解決這一切,你需要做的就是 編輯您的AppServiceProvider.php文件和引導方法內部設置一個默認 字符串長度:

use Illuminate\Support\Facades\Schema; 

public function boot(){ 
    Schema::defaultStringLength(191); 
} 

後一切都應該正常工作。

0
open create_user_tabel and then write one line inside up function. 
    Schema::defaultStringLength(191); 
e.g 

    public function up() 
    {  
     Schema::defaultStringLength(191); 

    Schema::create('users', function (Blueprint $table) { 
       $table->increments('id'); 
       $table->string('name'); 
       $table->string('email')->unique(); 
       $table->string('password'); 
       $table->rememberToken(); 
       $table->timestamps(); 
    } 

它將工作100%。

相關問題