Symfony Make:Migration : The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

Viewed 70108

I keep getting this problem everytime i try to migrate using the commandline: php bin/console make:migration or even doctrine:migration status when i try the doctrine:migration:sync-metadata-storage as they tell me I still get the same error message.

I'm currently learning symfony and have been following a guide but I get this problem somehow Symfony 4.4 php 7.2

20 Answers

Try changing the DATABASE_URL in .env from

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=10.4.11

to

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=mariadb-10.4.11

Symfony documentation suggest specifying the version number but not the database type

"There are more options in config/packages/doctrine.yaml that you can configure, including your server_version (e.g. 5.7 if you're using MySQL 5.7), which may affect how Doctrine functions." https://symfony.com/doc/current/doctrine.html

Original Answer: https://github.com/doctrine/DoctrineMigrationsBundle/issues/337#issuecomment-645390496

For MariaDB you will need the full semver compat version: Major.Minor.Patch. By executing mysql --version, you will get the correct version you are currently running.

It works if I change the DATABASE_URL in .env

From:

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=10.4.11

To:

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=mariadb-10.4.11

In my case, it works when I remove : ?serverVersion=5.2 , from the url.

you have to change the serverVersion=5.7 in .env to serverVersion=mariadb-10.4.8

I ran into the same issue after upgrading to Doctrine migrations 3

Seems that a lot of stuff has changed including the table name where migration versions are stored :(

So I updated config/packages/doctrine_migrations.yaml, created a new (blank) migration, cleared the cache (just in case) and everything went just fine :)

doctrine_migrations:
migrations_paths:
    # namespace is arbitrary but should be different from App\Migrations
    # as migrations classes should NOT be autoloaded
    'DoctrineMigrations': '%kernel.project_dir%/src/Migrations'
storage:
    # Default (SQL table) metadata storage configuration
    table_storage:
        table_name: 'migration_versions'
        version_column_name: 'version'
        version_column_length: 1024
        executed_at_column_name: 'executed_at'
        execution_time_column_name: 'execution_time'

BTW. Docs are up to date ;) https://symfony.com/doc/master/bundles/DoctrineMigrationsBundle/index.html

Symfony 5.1

if you got:

Invalid platform version "maridb-10.4.13" specified. The platform version has to be specified in the format: "<major_version>.<minor_version>.<patch_version>".

just do one of

config/doctrine.yaml

doctrine:
  dbal:
    server_version: 'mariadb-10.4.13'

or in configuration file .env

DATABASE_URL=mysql://databaseUsername:UserPassword@localhost:3306/databaseName?serverVersion=mariadb-10.4.13

Remove the server version in .env file DATABASE_URL=mysql://root:@127.0.0.1:3306/DB_Name

I've added serverVersion=mariadb-10.4.11 in the database URL string, and it worked.

for me it worked with me when i removed "?serverVersion=5.7" in .env file

from: DATABASE_URL="mysql://root:@127.0.0.1:3306/centre?serverVersion=5.7"

to DATABASE_URL="mysql://root:@127.0.0.1:3306/centre"

Same problem here.. I "sloved" it but dont try this at home!

I removed these lines in vendor\doctrine\migrations\lib\Doctrine\Migrations\Metadata\Storage\TableMetadataStorage.php start on line 191

$expectedTable = $this->getExpectedTable();

if ($this->needsUpdate($expectedTable) !== null) {
    throw MetadataStorageError::notUpToDate();
}

Then run make:migration and migrations:migrate. After success migration paste the function back.

I temporary resolved this problem by modifying the file: /vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Comparator.php

changed method diffColumn:

    // This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3
    if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) {
        array_shift($changedProperties);

        $changedProperties[] = 'comment';
    }

    //////////////////////////////////////////////////////////////////
    // This is my change for fix problem//////////////////////////////
    //////////////////////////////////////////////////////////////////
    if ($properties1['default'] === 'NULL') {
        $properties1['default'] = null;
    }
    if ($properties2['default'] === 'NULL') {
        $properties2['default'] = null;
    }
    /////////////////////////////////////////////////////////////////


    // Null values need to be checked additionally as they tell whether to create or drop a default value.
    // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
    if (($properties1['default'] === null) !== ($properties2['default'] === null)
        || $properties1['default'] != $properties2['default']) {
        $changedProperties[] = 'default';
    }

If you upgraded doctrine/doctrine-migrations-bundle to version 3, this solution worked for me:

Just run: php bin/console doctrine:migrations:sync-metadata-storage

In your .env file you can use a default settings pattern:

DATABASE_URL=mysql://db-username:db-password@127.0.0.1/db-name

But you need to configure server_version in doctrine.yaml

An example configuration can look like this:

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: 'mariadb-10.5.8-focal'
        charset: UTF8
        url: '%env(resolve:DATABASE_URL)%'

In my case, it's mariadb-10.5.8-focal.

just execute this command

symfony console cache:clear

it solve the problem for me a

In my case (MariaDB 10.7.3) setting ?serverVersion=mariadb-10.7.3 didn't help.

I had to uninstall MariaDB 10.7.3 and install MySQL Community 8.0.28 instead, and then changed DATABASE_URL to ?serverVersion=8.0.28

Only switching from MariaDB to MySQL Community fixed this problem for me.

change

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=10.4.11

To

DATABASE_URL=mysql://root:@127.0.0.1:3306/testtest?serverVersion=mariadb-10.4.11

in your .env file at the database line remove everything after the database name. This should fix the problem!

Related