Lumen 5.6 Migrate Error Specified key was too long max key length is 767 bytes

会有一股神秘感。 提交于 2020-01-01 10:15:09

问题


I use Lumen 5.6 and mysql. when i type "php artisan migrate" following error occur:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t  
oo long; max key length is 767 bytes (SQL: alter table `users` add unique `  
users_email_unique`(`email`))  

I put following code into "boot" method in the AppServiceProvider

Schema::defaultStringLength(191);

but I didn't achieve to any success.


回答1:


you just need one more step

go to app.php on bootstrap folder and uncomomment or modif this line

// $app->register(App\Providers\AppServiceProvider::class);

to this code

$app->register(App\Providers\AppServiceProvider::class);

have a good day




回答2:


use Illuminate\Support\Facades\Schema; //AppServiceProvider.php

public function boot(){
Schema::defaultStringLength(191);
}

//rollback your migration or delete all table from database then migrate again.



回答3:


Go to config in file database.php then edit

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

to

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',



回答4:


You need couple of things to do. I also faced this issue and fixed it by following these two steps

  1. Go to app.php in bootstrap directory and uncomment or modify this line.

    // $app->register(App\Providers\AppServiceProvider::class);
    
  2. Now you need to define boot()function in AppServiceProviderfile

        public function boot()
        {
           Schema::defaultStringLength(191);
        }
    

Then you are good to go!




回答5:


  1. in bootstrap/app.php un-comment this line:
$app->register(App\Providers\AppServiceProvider::class);
  1. in app/AppServiceProvider.php add below public function to AppServiceProvider class:
public function boot()
  {
    Schema::defaultStringLength(191);
  }


来源:https://stackoverflow.com/questions/51169760/lumen-5-6-migrate-error-specified-key-was-too-long-max-key-length-is-767-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!