Why default value is setting for every doctrine migration?
Asked Answered
P

1

7

I use Symfony 2.7, doctrine/orm 2.5 and doctrine-bundle 1.5. In Cargo entity I have property price:

    /**
     * @var float
     *
     * @ORM\Column(name="price", type="float", options={"unsigned":true, "default":0})
     */
    protected $price;

In every doctrine migration class I have:

$this->addSql('ALTER TABLE cargo CHANGE price price DOUBLE PRECISION DEFAULT \'0\' NOT NULL');

Despite that previously migration has been executed and default value for price has already set. Why that happens and how to fix it? Or it is better directly set default value to property? According to Doctrine documentation both options are available:

Prioress answered 6/4, 2016 at 17:6 Comment(0)
G
0

It's because your database converts 0 default value to 0.00. When \Doctrine\DBAL\Schema\Comparator::compareTables tries to compare current schema with expected one - it founds that those columns declaration are not the same: NUMERIC(10, 2) DEFAULT '0.00' NOT NULL vs NUMERIC(10, 2) DEFAULT '0' NOT NULL (from \Doctrine\DBAL\Platforms\AbstractPlatform::columnsEqual)

So the solution is to use the same format in default value as your database does - options={"unsigned":true, "default":"0.00"})

Godmother answered 1/9, 2023 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.