如何解决“密钥过长”错误并生成“学说”迁移表?

问题描述

我正在使用/设置配置如下的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