laravel常见问题

2017-09-13  本文已影响0人  Jack张ok

1,php artisan migrate 出现

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

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

解决方案:
我们可以在 AppServiceProvider.php 文件里的 boot 方法里设置一个默认值:
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

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

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

}

上一篇下一篇

猜你喜欢

热点阅读