美文网首页
laravel常见问题

laravel常见问题

作者: Jack张ok | 来源:发表于2017-09-13 10:24 被阅读0次

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

    }

    相关文章

      网友评论

          本文标题:laravel常见问题

          本文链接:https://www.haomeiwen.com/subject/wcrksxtx.html