Doctrine(2.12) keeps generating the same migration for a property using columnDefinition

Viewed 35

I created an apiplatform 3.0, symfony 6.1 app. It has a docker environment with mysql 8.0.

Using the new features in doctrine 2.11, I created 2 properties:

trait TraitName
{
    #[ORM\Column(insertable: false, updatable: false, columnDefinition: 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP', generated: 'INSERT')]
    private \DateTimeImmutable $createdAt;

    #[ORM\Column(insertable: false, updatable: false, columnDefinition: 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', generated: 'ALWAYS')]
    private \DateTimeImmutable $updatedAt;
}

They also have their own getter.

When I make a migration and migrate. Everything goes well. The app is running fine.
But everytime I do doctrine:schema:validate, it says The database schema is not in sync with the current mapping file.
And if I do a make:migration it keeps on creating the same migration:

$this->addSql('ALTER TABLE table1 CHANGE created_at created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE updated_at updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE table2 CHANGE created_at created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE updated_at updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE table3 CHANGE created_at created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CHANGE updated_at updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');

I tried moving it out of the trait, it does not change anything.

I read that it could be the serverVersion or an issue with the driver definition(when using mariaDb which it is not the case here)
The DATABASE_URL is defined as such in the compose.yaml:

DATABASE_URL: mysql://user:password@database:3306/dbname?serverVersion=5.7

doctrine.yaml:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
0 Answers
Related