2
votes

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'
2
Please share your configuration. According to github.com/doctrine/DoctrineMigrationsBundle/issues/247, you can use way less than 1024 charactersNico Haase
Also, please share a full stack trace for the second error messageNico Haase
Edited with requested informationsTikTaZ
Which version of that migrations bundle do you use?Nico Haase
The latest 2.2.0, i add the information in my questionTikTaZ

2 Answers

4
votes

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

0
votes

This happens because of the key length limitation in the MySQL version used. It could be lesser with older versions of MySQL and also depend on the collation used. You'll have to check with the MySQL version you are using to find the maximum key length allowed and then find the maximum size of a column that could be used with the collation that is being used. That length could be used in the option version_column_length in the configuration s file of doctrine migrations (eg: migrations.php or migrations.xml etc...).

Good explanation about max length of the key could be found in the answer of following question.

Specified key was too long; max key length is 767 bytes

In my case it was limited 191 because I was using MySQL 5.6