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

前端 未结 6 1396
生来不讨喜
生来不讨喜 2021-02-14 16:45

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         


        
相关标签:
6条回答
  • 2021-02-14 17:30

    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

    0 讨论(0)
  • 2021-02-14 17:35

    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!

    0 讨论(0)
  • 2021-02-14 17:38

    Go to config in file database.php then edit

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

    to

    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    
    0 讨论(0)
  • 2021-02-14 17:42
    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);
      }
    
    0 讨论(0)
  • 2021-02-14 17:44

    Known to work in Laravel/Lumen 7.x:

    I've tried the un-commenting of AppServiceProvider::class and other solutions mentioned above, but the following worked for me.

    If you look in /vendor/laravel/lumen-framework/config/database.php for charset and collation, the code checks your .env file and resorts to utf8mb4 and utf8mb4_unicode_ci, respectively.

    If your database' charset is set to utf8 and collation to utf8_unicode_ci, simply add the following to your .env file:

    # .env
    ...
    DB_CHARSET=utf8
    DB_COLLATION=utf8_unicode_ci
    ...
    
    0 讨论(0)
  • 2021-02-14 17:46
    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.
    
    0 讨论(0)
提交回复
热议问题