【问题标题】:How to fix the "key too long" error and generate the Doctrine migrations table?如何修复“key too long”错误并生成 Doctrine 迁移表?
【发布时间】:2021-02-19 07:14:29
【问题描述】:

我正在使用/设置 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 Desktop 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 表?

【问题讨论】:

    标签: symfony doctrine-orm symfony-3.4 doctrine-migrations


    【解决方案1】:

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

    删除配置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
    

    【讨论】:

      猜你喜欢
      • 2017-08-26
      • 2019-12-18
      • 1970-01-01
      • 2021-09-23
      • 1970-01-01
      • 2019-10-04
      • 2014-08-10
      • 2019-06-26
      • 2017-02-18
      相关资源
      最近更新 更多