dragon7088
2018-05-11 00:06
浏览 112
已采纳

PHP Laravel迁移SQL问题[重复]

When I was performing php artisan migrate on cmd in my laravel project. I'm getting the below error. Please help.enter image description here

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dpj0015 2018-05-11 06:39
    已采纳
    laravel 5.4.* file location : app/Providers/AppServiceProvider.php
    

    AppServiceProvider.php It has been modified

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

    After that execute the migrate Artisan command:

    php artisan migrate
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doudou348131346 2018-05-11 00:12

    In AppServiceProvider.php which is located in (app/Providers) add this

    use Illuminate\Support\Facades\Schema;
    
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    
    评论
    解决 无用
    打赏 举报
  • drau67562 2018-05-11 00:13

    You might be running into the index length configuration.

    The laravel documentation states the following

    Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them. You may configure this by calling the Schema::defaultStringLength method within your AppServiceProvider:

    use Illuminate\Support\Facades\Schema;
    
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    
    评论
    解决 无用
    打赏 举报
  • dovgqc2648 2018-05-11 02:35

    The error occurs because of the email is using unique() but it doesn't know how long is your unique value.. You have two ways to solve this

    The first is set in global in your App\Providers\AppServiceProvider.php and then add your code in boot method:

    use Illuminate\Support\Facades\Schema;
    
    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    

    The second is only set in your migration table, you only need to specify the length of the string like:

    $table->string('email', 191)->unique();
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题