Laravel-admin: 数据库创建特殊字符过长问题

Created on 27 Dec 2017  ·  7Comments  ·  Source: z-song/laravel-admin

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添加默认值

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

Most helpful comment

这个问题是laravel的问题,我建议在这个组件的wiki文档里面也带上这么个说明,能让第一次安装的人避开这个问题

All 7 comments

这个问题是laravel的问题,我建议在这个组件的wiki文档里面也带上这么个说明,能让第一次安装的人避开这个问题

遇到这个问题,根据这个帖子的方法操作后,然后需要删除已经生成的两张数据表,才能php artisan admin:install重新进行

有生成表吗?库吗?没看见啊

有生成表吗?库吗?没看见啊

有 migrate表已经生成,user表也有了,

按照教程,正解

或者指定mysql数据库引擎默认为InnoDB。

踩到这个坑里了,不过 email 设置为 255 的长度加上唯一索引,其索引效率是不是不太高,比如单个数据分页、redo日志页存放的数据数量,Buffer缓冲区可存放的页之类的都有些影响,我这边是暂时改为 100 解决掉了。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fokoz picture fokoz  ·  3Comments

MarKco picture MarKco  ·  3Comments

clock1129 picture clock1129  ·  3Comments

abufalbo picture abufalbo  ·  3Comments

greentornado picture greentornado  ·  3Comments