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

I’m using / setting up the Symfony DoctrineMigrationsBundle v2.2 configured as followed:

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

The RDBMS is MySQL v8, running (locally) on Ubuntu Desktop v20.04:

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

The DEFAULT_CHARACTER_SET_NAME is utf8mb4, the DEFAULT_COLLATION_NAME is utf8mb4_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     |
+----------------------------+------------------------+

While I was playing with the configs, I created two migrations tables (I changed the doctrine_migrations.storage.table_storage.table_name multiple times), somehow… Now, after the configuration has bee completed I want to go the setup through cleanly again from scratch. So I removed both migrations tables and started again. But now I’m getting following error:

$ ./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

I tried to reduce the doctrine_migrations.storage.table_storage.version_column_length, but then I’m running in another error:

$ ./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.

How to set this up correctly and get the migrations tables generated?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *