解决Larabel迁移文件报SQLSTATE[42000]错误

PHP 投稿 66900 0 评论

解决Larabel迁移文件报SQLSTATE[42000]错误

Laravel 命令执行 php artisan migrate 命令时,报错:

Illuminate\Database\QueryException  : 

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`(`email`))

解决方法

修改 app/Providers/AppServiceProvider.php 文件中添加如下内容:

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
    }
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
}

修改部分

Schema::defaultStringLength(191);

编程笔记 » 解决Larabel迁移文件报SQLSTATE[42000]错误

赞同 (64) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽