68

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

Waqleh
  • 9,741
  • 8
  • 65
  • 103
Aziz Bouaouina
  • 791
  • 1
  • 5
  • 4

21 Answers21

173

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.

kaiser
  • 21,817
  • 17
  • 90
  • 110
Mees van Wel
  • 1,393
  • 1
  • 7
  • 13
  • What servertype are you using then? – Mees van Wel Jun 23 '20 at 18:44
  • Well i use mysql – vincent PHILIPPE Jun 23 '20 at 18:46
  • If you use XAMPP you can go to: http://localhost/phpmyadmin/index.php to check your server version and type. – Mees van Wel Jun 24 '20 at 08:05
  • in my case I was using docker so I had to do the same under `environment` in `docker-compose.yml` – Waqleh Aug 29 '20 at 17:25
  • I'm using mariadb 10.5.5 and this fixed the error for me. – Naumdev Sep 07 '20 at 19:25
  • Work for me. I use in my localhost Xampp with mariadb. – Jorge H Sep 24 '20 at 21:08
  • 5
    Simply execute "SELECT VERSION()" on your mariaDB server and use this string as version in your config. In my case ?serverVersion=10.3.25-MariaDB-0+deb10u1 and it works. – Dado Nov 06 '20 at 04:40
  • prefixing the server version as 'mariadb-10.5.11' or with SELECT VERSION() result '10.5.11-MariaDB-1:10.5.11+maria~focal' doesn't work for me, as a matter of fact any of the proposed solutions work for me except the one proposed by @hashtag-assist. Commenting file vendor lines avoid the error, but editing a vendor file doesn't seem a good solution to me. Are there any other working solution today? – Alex Jul 14 '21 at 11:14
36

For me was enough prefixing the server version with mariadb-x.x.x. It fixed the issue.

"If you are running a MariaDB database, you should prefix the serverVersion with mariadb- (ex: mariadb-10.2.12)."

https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url

utidevid
  • 393
  • 3
  • 6
  • This fixed the issue instantly without having to rewrite config. – VPZ Jun 18 '20 at 05:18
  • For more details: see https://github.com/doctrine/DoctrineMigrationsBundle/issues/337#issuecomment-645390496 And https://github.com/doctrine/DoctrineMigrationsBundle/pull/398 to add a documentation to the bundle itself – thePanz Jan 26 '21 at 16:31
  • Thanks, you solved a long-running issue we had after upgrading to PHP 8.1! – YetiCGN Sep 19 '22 at 14:00
20

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
HectorJ
  • 5,814
  • 3
  • 34
  • 52
Mohammad Ali
  • 309
  • 1
  • 5
17

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

jally-ph
  • 171
  • 2
10

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

Michael Hirschler
  • 2,345
  • 16
  • 28
Mousroot
  • 101
  • 3
10

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
zoore
  • 293
  • 5
  • 13
  • I cannot upvote this answer enough. Really wasn't aware that you must specify server_version: 'mariadb-...'. – Mecanik Nov 06 '21 at 07:45
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

elkuku
  • 81
  • 4
  • This works for me! Thanks. The "funny" part: I actually had a new project from scratch and got this error, so there was no update. I use Symfony & Doctrine from the beginning. – Braincompiler Jun 17 '20 at 08:22
  • 1
    Hang on! I take everything back ... :( The command `make:migration` worked again after I added the storage config to the doctrine_migrations.yaml but `doctrine:migrations:migrate` brought me back to the error: "The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue.". The same error I get if I run the `doctrine:migrations:sync-metadata-storage` ... – Braincompiler Jun 17 '20 at 08:27
  • 2
    If use MySQL you need set version_column_length: 255 – Bukashk0zzz Jun 23 '20 at 12:38
  • 1
    What should we put instead of 'migration_versions', 'version', 1024... @Bukashk0zzz says that you have to use version_column_length: 255 if using mysql, but where did you see that ? – vincent PHILIPPE Jun 25 '20 at 09:30
  • Because it tries to create an index. And the full search index length in Mysql can only be 255 – Bukashk0zzz Jun 25 '20 at 12:18
5

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

Salma Elshahawy
  • 1,112
  • 2
  • 11
  • 21
TheTurTel500
  • 49
  • 1
  • 3
2

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"

2

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
1

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

khadijaiig
  • 19
  • 3
0

I have the same problem it is because of the new version of doctrine migration 3.0

php bin/console  debug:config DoctrineMigrationsBundle 

https://symfony.com/doc/master/bundles/DoctrineMigrationsBundle/index.html

bfx
  • 1
0

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.

Mikhail Prosalov
  • 4,155
  • 4
  • 29
  • 41
hashtag-assist
  • 402
  • 6
  • 12
  • prefixing the server version as 'mariadb-10.5.11' doesn't work for me, as a matter of fact any of the proposed solutions work for me except this one. Commenting this lines avoid the error, but editing a vendor file doesn't seem a good solution to me. Are there any other working solution today? – Alex Jul 14 '21 at 11:09
  • Not sure what I should look for on GitHub. So I came to StackOverflow directly to ask. – Alex Jul 16 '21 at 07:52
  • https://github.com/doctrine/DoctrineMigrationsBundle/issues/337 – hashtag-assist Jul 16 '21 at 17:36
0

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';
    }
ildar
  • 1
  • 1
0

https://symfony.com/doc/master/bundles/DoctrineMigrationsBundle/index.html

follow the instructions to the letter

composer require doctrine/doctrine-migrations-bundle

php bin/console doctrine:migrations:generate

php bin/console doctrine:migrations:status --show-versions

php bin/console doctrine:migrations:migrate

everything worked for me

0

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

Samuel Vicent
  • 991
  • 10
  • 16
0

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.

Łukasz D. Tulikowski
  • 1,440
  • 1
  • 17
  • 36
0

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

jmoerdyk
  • 5,544
  • 7
  • 38
  • 49
  • 1
    Please write your answer in English, as Stack Overflow is an [English-only site](//meta.stackoverflow.com/a/297680). – jmoerdyk Apr 25 '22 at 17:43
0

I tried all of these solutions. In Symfony 6.x version all of these solutions aren't working. But I removed symfony/web-profiler-bundle package and everything is fine now. Actually I don't need any profiler. Thanks symfony. I hope you spend my another days in the future.

I will escape from PHP because of symfony framework in near future.

kodmanyagha
  • 932
  • 12
  • 20
-1

just execute this command

symfony console cache:clear

it solve the problem for me a

yesser
  • 1
  • 3
-1

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.

Ilyich
  • 4,966
  • 3
  • 39
  • 27