Laravel5 Syntax error or access violation: 1071 Specified key was too long; max key length is 1000

版权声明:版权归qq175023117所有 https://blog.csdn.net/qq175023117/article/details/86066925

新创建了个laravel5框架,然后安装laravel-admin并运行migration的时候出现了如下报错问题

 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 (SQL: alter table `users` add unique `users_email_unique`(`emai
  l`))


In PDOStatement.php line 119:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes


In PDOStatement.php line 117:

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

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

laravel 5.4 改变了默认的数据库字符集,现在utf8mb4包括存储emojis支持。如果你运行MySQL v5.7.7或者更高版本,则不需要做任何事情。

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

这个问题是laravel的问题,看到这个文章,能让第一次安装的人避开这个问题

如已解决此问题,可选择查看laravel-admin的各种小技巧,迈过新手的坑:https://blog.csdn.net/qq175023117/article/details/80681533

猜你喜欢

转载自blog.csdn.net/qq175023117/article/details/86066925