Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库创建特殊字符过长问题 #1541

Closed
StringKe opened this issue Dec 27, 2017 · 9 comments
Closed

数据库创建特殊字符过长问题 #1541

StringKe opened this issue Dec 27, 2017 · 9 comments

Comments

@StringKe
Copy link

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()
    {
        //
    }
}
@jianfengye
Copy link
Contributor

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

@z-song z-song closed this as completed Sep 14, 2018
@zjairing
Copy link

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

@1349859051
Copy link

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

@xin6841414
Copy link

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

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

@Liuck
Copy link

Liuck commented May 4, 2020

按照教程,正解

@comsummer
Copy link

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

@wangerzi
Copy link

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

@woshixiaobaitv
Copy link

如果楼主介绍的方法还不行可以尝试使用如下两个方法
一,在laravel配置文件中
`
// config/database.php
'mysql' => [
...
'engine' => 'InnoDB',
...
]

二,在 mysql配置文件 my.ini中(注意存盘重启)
//在mysql的配置文件my.ini中设置
default-storage-engine=InnoDB
innodb-default-row-format=dynamic
//restart
`

@zjairing
Copy link

zjairing commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants