laravel-admin php artisan admin:install報錯問題解決辦法


問題描述:根據laravel-admin官方文檔安裝步驟,執行:php artisan admin:install 安裝時報錯。

其實是數據庫創建特殊字符過長問題,laravel 5.4 改變了默認的數據庫字符集,現在utf8mb4包括存儲emojis支持。如果你運行MySQL v5.7.7或者更高版本,則不需要做任何事情。

當你試着在一些MariaDB或者一些老版本的的MySQL上運行 migrations 命令時,你可能會碰到下面這個錯誤:

D:\wwwroot\www.test.com>php artisan admin:install Migration table created successfully. In Connection.php line 664: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (S QL: alter table `users` add unique `users_email_unique`(`email`)) In Connection.php line 458: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

解決方案在app\Providers\AppServiceProvider.php添加默認值,需要刪除數據庫migrations、users表。重新執行:php artisan admin:install

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema; //add fixed sql

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191); //add fixed sql
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

參考這個issue:https://github.com/z-song/laravel-admin/issues/1541


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM