Symfony Migrations Bundle creating the same migration over and over again - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, March 30, 2023

Symfony Migrations Bundle creating the same migration over and over again

I added an auto-update timestamp to an entity like in this blog post and it works just fine.

Here is the code snippet:

#[Entity]
class Article
{
    #[Column(type: "datetime",
        columnDefinition: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        insertable: false,
        updatable: false,
        generated: "ALWAYS")]
    public $created;
}

The first time I run php bin/console make:migration the correct migration is generated:

$this->addSql('ALTER TABLE article ADD created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');

This works just fine and any DB update now updates created. However, this is also where the problems begin. Whenever I make another migration now, it tries to apply the same changes again:

$this->addSql('ALTER TABLE article CHANGE created created TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');

How can this be, and does anyone know how to fix this?

Thank you very much for your input, I really appreciate it.



source https://stackoverflow.com/questions/75869478/symfony-migrations-bundle-creating-the-same-migration-over-and-over-again

No comments:

Post a Comment