Symfony 6 / Doctrine / Migration: [ERROR] The database schema is not in sync with the current mapping file

534 Views Asked by At

I build an App in Symfony 6.2 and have it running on a Raspberry Pi. Here are the prerequisites:

Local:

  • OS: Ubuntu 20.04.6 LTS
  • DB: Ver 15.1 Distrib 10.10.5-MariaDB
  • PHP: 8.2.7

Server (Pi):

  • OS: Debian GNU/Linux 11 (bullseye)
  • DB: Ver 15.1 Distrib 10.5.19-MariaDB
  • PHP: 8.2.7

Lately I made a minor change on an Entity and added a new member. So I followed my standard procedure.

Create migration

$ php bin/console doctrine:migrations:diff

Code of migration

final class Version20230618154133 extends AbstractMigration
{
    public function getDescription(): string
    {
        return '';
    }

    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE submission ADD status_has_not_reacted TINYINT(1) NOT NULL');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE submission DROP status_has_not_reacted');
    }
}

After pushing the change and run Jenkins to build an archive, I extracted that in staging, imported the production database and ran the command

php bin/console doctrine:migrations:migrate

which ran successful.

Afterwards I ran

php bin/console doctrine:schema:validate

to check if everything is in order. But this time it throws this error Syncing Error

Weird thing is, that there are basically no changes to what I normally did, which worked fine. The only thing that did change in the DB was the version of MariaDB on the server from 10.5.18 > 10.5.19, but since this is a minor release, I don't think this is causing the trouble.

config/packages/doctrine.yaml

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

doctrine:
    dbal:
        dbname: '%env(DB_NAME)%'
        host: '%env(DB_HOST)%'
        user: '%env(DB_USER)%'
        password: '%env(DB_PASSWORD)%'
        server_version: 'mariadb-10.10.5'
        charset: utf8mb4
        logging: '%kernel.debug%'
        options:
            platform: mariadb
        types:
            datetime_immutable: \Carbon\Doctrine\DateTimeImmutableType
            datetime: \Carbon\Doctrine\DateTimeType
    orm:
        auto_generate_proxy_classes: true
        enable_lazy_ghost_objects: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true

        dql:
            datetime_functions:
                YEAR: DoctrineExtensions\Query\Mysql\Year


when@prod: &doctrine_prod
    doctrine:
        dbal:
            server_version: mariadb-10.5.19

when@staging: *doctrine_prod

The migration went fine, so I tried the command to double-check:

php bin/console doctrine:migrations:list

which led to this Metadata error

So I tried the following:

  • in config/packages/doctrine.yaml I changed the server_version parameter to the newer version
  • I used the "doctrine:migrations:sync-metadata-storage" which ran successful
    • I compared the "doctrine_migration_versions" table if something changed in the database, but it did not
  • I tried to use the a string connection string with "mariadb-10.5.19" in the .yaml-file
  • I checked if my last apt-upgrade on the server had any critical updates, but it only was a switch from PHP 8.2.5 > 8.2.7
  • I checked the changelogs of MariaDB and PHP versions which did imo did not contain critical changes

Locally the new schema is valid and works as expected. On the server the schema is not valid, but it also works as expected. So the new member of the entity is respected, but somehow the mapping is not correct.

One odd thing happened when I wiped all migrations and dumped it into one on the server. It suddenly used the MySQL platform over the MariaDB platform which is weird since I defined the platform in the config and I'm running MariaDB as well. DBAL platforms

When I update the schema with

php bin/console doctrine:schema:update --complete --dump-sql

it shows this, which I'm not sure what to do with... (and even when I execute this, the error remains).

DROP TABLE doctrine_migration_versions;
ALTER TABLE vendor CHANGE updated_at updated_at DATETIME(6) DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)', CHANGE last_name last_name VARCHAR(255) DEFAULT NULL, CHANGE alternative_emails alternative_emails LONGTEXT DEFAULT NULL COMMENT '(DC2Type:simple_array)', CHANGE paypal paypal VARCHAR(255) DEFAULT NULL, CHANGE brand brand VARCHAR(255) DEFAULT NULL, CHANGE website website VARCHAR(255) DEFAULT NULL, CHANGE main_category main_category VARCHAR(255) DEFAULT NULL;
ALTER TABLE market CHANGE updated_at updated_at DATETIME(6) DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)', CHANGE info_facebook_event info_facebook_event VARCHAR(255) DEFAULT NULL, CHANGE banned_submissions banned_submissions LONGTEXT DEFAULT NULL COMMENT '(DC2Type:simple_array)';
ALTER TABLE submission CHANGE main_category main_category VARCHAR(255) DEFAULT NULL, CHANGE updated_at updated_at DATETIME(6) DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)', CHANGE color_code color_code VARCHAR(255) DEFAULT NULL, CHANGE vendor_last_name vendor_last_name VARCHAR(255) DEFAULT NULL, CHANGE vendor_paypal vendor_paypal VARCHAR(255) DEFAULT NULL, CHANGE vendor_brand vendor_brand VARCHAR(255) DEFAULT NULL, CHANGE vendor_website vendor_website VARCHAR(255) DEFAULT NULL, CHANGE assignment_designation assignment_designation VARCHAR(255) DEFAULT NULL, CHANGE assignment_table_id assignment_table_id VARCHAR(255) DEFAULT NULL, CHANGE assignment_table_position assignment_table_position VARCHAR(255) DEFAULT NULL, CHANGE status_screening status_screening VARCHAR(255) DEFAULT 'unseen' NOT NULL;
ALTER TABLE comment CHANGE author author VARCHAR(255) DEFAULT NULL;
ALTER TABLE mail CHANGE created_at created_at DATETIME(6) DEFAULT NULL COMMENT '(DC2Type:datetime_immutable)';

Thanks in advance for any clue. I'm still a beginner and every hint is welcome at this point :) Please let me know if anything important in my description is missing. THANKS!!

0

There are 0 best solutions below