symfonydoctrine-migrations

Doctrine table migrations_versions column length


On Symfony 5 with Doctrine Migrations 2.2.0 I want to execute a custom doctrine migration file. My entities are created with InnoDB utf8mb4_unicode_ci (default value in doctrine.yaml).

When I execute bin/console doctrine:migrations:status --show-versions I get :

An exception occurred while executing 'CREATE TABLE migration_versions (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

So I modify doctrine_migrations.yaml and changed version_column_length's value to 255 but now with the same command I get

In BaseNode.php line 425:                                                                                                                                
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 187:
The minimum length for the version column is 1024.  

It's possible to change varchar length of automatically created entities tables to 1024 so it's a not a restriction from my db. How could I create automatically the migrations_versions table with the proper column length ?

config/packages/doctrine.yaml

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        mapping_types:
          enum: string

        # IMPORTANT: You MUST configure your server version,
        # either here or in the DATABASE_URL env var (see .env file)
        #server_version: '5.7'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

config/packages/doctrine_migrations.yaml

doctrine_migrations:
    migrations_paths:
        'DoctrineMigrations': '%kernel.project_dir%/src/Migrations'
    storage:
        table_storage:
            table_name: 'migration_versions'
            version_column_name: 'version'
            version_column_length: 1024
            executed_at_column_name: 'executed_at'

Solution

  • My coworker found the solution by simply comment the line version_column_length: 1024