php 未使用Laravel将表迁移到数据库中

x6h2sr28  于 2023-01-24  发布在  PHP
关注(0)|答案(1)|浏览(139)

我是Laravel的新手,我正在使用“Laravel版本9”(最新),我运行以下命令,但给我以下错误

Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

我有4个文件内“数据库/迁移”,然后我运行“php工匠服务”命令,但只有“两个表”插入到数据库(用户(空)和迁移),我怎么能添加表的其余部分?我尝试了以下代码内“/app/Providers/AppServiceProvider.php”,但仍然得到相同的错误,我该如何解决这个问题?

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

oaxa6hgo1#

在文件config/database.php中,找到关键字mysql并添加行

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

应该看起来像这样:

'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'modes' => [
            'ONLY_FULL_GROUP_BY',
            'STRICT_TRANS_TABLES',
            'NO_ZERO_IN_DATE',
            'NO_ZERO_DATE',
            'ERROR_FOR_DIVISION_BY_ZERO',
            'NO_AUTO_CREATE_USER',
            'NO_ENGINE_SUBSTITUTION'
        ],
        'engine' => 'InnoDB ROW_FORMAT=DYNAMIC', // this line
    ],

相关问题