symfonydoctrine-ormdoctrine-migrations

Why default value is setting for every doctrine migration?


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:


Solution

  • 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"})