Doctrine custom type always altering table

doctrine-orm, symfony

Solution

You have to override the method `requiresSQLCommentHint(AbstractPlatform $platform)` and return `true`. Like that, doctrine will remember the custom type.

namespace My\SuperBundle\Types;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class Money extends Type
{
    const MONEY = 'money';

    public function getSqlDeclaration(
        array $fieldDeclaration,
        AbstractPlatform $platform
    ) {
        return 'DECIMAL(10,2)';
    }

    public function getName()
    {
        return self::MONEY;
    }

    /**
     * @inheritdoc
     */
    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }
}

Source: Use column comments for further Doctrine Type Inference

Problem

I have added a custom type like: ``` namespace My\SuperBundle\Types; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; class Money extends Type { const MONEY = 'money'; public function getSqlDeclaration( array $fieldDeclaration, AbstractPlatform $platform ) { return 'DECIMAL(10,2)'; } public function getName() { return self::MONEY; } } ``` And in my application boot: ``` namespace My\SuperBundle; use Doctrine\DBAL\Types\Type; use My\SuperBundle\Types\Money; class MyBSuperBundle extends Bundle { public function boot() { //add custom quantity and wight types $em = $this->container->get('doctrine.orm.entity_manager'); if(!Type::hasType(Money::MONEY)) { Type::addType(Money::MONEY, 'My\SuperBundle\Types\Money'); } } } ``` However every time I update the database with: ``` php app/console doctrine:schema:update --dump-sql ``` I keep getting the following: ``` ALTER TABLE product_price CHANGE price price DECIMAL(10,2) DEFAULT NULL ``` Apart from that everything works super fine. The fields in the DB are correct. Is there a reason why doctrine keeps updating with the same data?

Original source