如何修复 "key too long" 错误并生成 Doctrine 迁移 table?

How to fix the "key too long" error and generate the Doctrine migrations table?

我正在使用/设置 Symfony DoctrineMigrationsBundle v2.2 配置如下:

doctrine_migrations:
  name: 'My Migrations'
  migrations_paths:
    'DoctrineMigrations': '%kernel.project_dir%/src/Migrations'
  storage:
    table_storage:
      table_name: 'migrations'
      version_column_name: 'version'
      version_column_length: 1024
      executed_at_column_name: 'executed_at'
      # Seems not to be supported:
      # Unrecognized option "execution_time_column_name" under "doctrine_migrations.storage.table_storage"
      # execution_time_column_name: 'execution_time'
  organize_migrations: false
  # custom_template: ~
  all_or_nothing: false

RDBMS MySQL v8,运行(本地)在 Ubuntu 桌面 v20.04:

$ mysql --version
mysql  Ver 8.0.22-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

DEFAULT_CHARACTER_SET_NAMEutf8mb4DEFAULT_COLLATION_NAMEutf8mb4_unicode_ci:

SELECT
    `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`
FROM
    `INFORMATION_SCHEMA`.`SCHEMATA` 
WHERE
    `SCHEMA_NAME` = "payment"
;

+----------------------------+------------------------+
| DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME |
+----------------------------+------------------------+
| utf8mb4                    | utf8mb4_unicode_ci     |
+----------------------------+------------------------+

当我在玩配置时,我创建了两个迁移表(我多次更改 doctrine_migrations.storage.table_storage.table_name),不知何故......现在,在蜜蜂配置完成后我想通过设置从头开始干净利落。所以我删除了两个迁移表并重新开始。但现在我收到以下错误:

$ ./bin/console doctrine:migrations:status
...
In AbstractMySQLDriver.php line 106:
                                                                                                                                                                                                                  
  An exception occurred while executing 'CREATE TABLE migrations (version VARCHAR(1024) NOT NULL, executed_at DATETIME NOT NULL COMMENT '(DC2Type:datetime_immutable)', PRIMARY KEY(version)) DEFAULT CHARACTER   
  SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB':                                                                                                                                                        
                                                                                                                                                                                                                  
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes                                                                                                
                                                                                                                                                                                                                  

In PDOConnection.php line 43:
                                                                                                                    
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes  
                                                                                                                    

In PDOConnection.php line 41:
                                                                                                                    
  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes

我试图减少 doctrine_migrations.storage.table_storage.version_column_length,但后来 运行 出现另一个错误:

$ ./bin/console doctrine:migrations:status
...
In BaseNode.php line 348:
                                                                                                                                                        
  Invalid configuration for path "doctrine_migrations.storage.table_storage.version_column_length": The minimum length for the version column is 1024.  
                                                                                                                                                        

In ExprBuilder.php line 189:
                                                      
  The minimum length for the version column is 1024.

如何正确设置并生成 migrations 表?

这不是一个(干净的)解决方案,但至少是一个解决方法:

删除配置 doctrine_migrations.storage.table_storage.version_column_length 使其再次工作。生成的配置如下所示:

$ bin/console debug:config doctrine_migrations
...
Current configuration for extension with alias "doctrine_migrations"
====================================================================

doctrine_migrations:
    name: 'My Migrations'
    migrations_paths:
        DoctrineMigrations: /var/www/html/src/Migrations
    storage:
        table_storage:
            table_name: migrations
            version_column_name: version
            executed_at_column_name: executed_at
            version_column_length: null
    organize_migrations: false
    all_or_nothing: false
    dir_name: /var/www/html/src/bundles/Wings/DoctrineMigrations
    namespace: Application\Migrations
    table_name: migration_versions
    column_name: version
    column_length: 14
    executed_at_column_name: executed_at
    custom_template: null