How to fix MySql: index column size too large (Laravel migrate)

前端 未结 8 1347
北荒
北荒 2020-12-01 04:34

I duplicated a project with a vagrant box which installs Debian, Nginx, PhpMyAdmin, .. With the new project the Laravel\'s php artisan migrate is not working an

相关标签:
8条回答
  • 2020-12-01 05:28

    By default MySQL uses the character set utf8 which means that we use 3 bytes for every 1 character. This means, column type of varchar(10) uses 30 bytes resulting in the max prefix size for compact row format to be equivalent to varchar(255). That is 255 * 3bytes = 765 bytes which is, two bytes less than the max of 767 bytes.

    With innodb_large_prefix set to on and using row format COMPRESSED or DYNAMIC, you can increase the max prefix character size to 65536 bytes instead of 767 bytes. The below chart shows the max character length with InnoDB large prefix and [COMPRESSED| DYNAMIC] row formats. These values, expect for utf8mb4, are higher than the maximum row size of a table, so there is no way to hit these limits

    More info here https://discuss.pivotal.io/hc/en-us/articles/115004086747-Apps-are-down-due-to-the-Maximum-Column-Size-is-767-bytes-Constraint-in-MySQL

    0 讨论(0)
  • 2020-12-01 05:29

    In App\Providers\AppServiceProvider.php, import Schema

    use Illuminate\Support\Facades\Schema;
    

    and in the boot() function add this line:

    Schema::defaultStringLength(191);
    
    0 讨论(0)
提交回复
热议问题