我创建了一个自定义的教义类型,如http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.html中所述

这是代码:

<?php

namespace XXX\Bundle\XXXBundle\Doctrine\Type;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateTimeType;

class UTCDateTimeType extends DateTimeType
{
    static private $utc = null;

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if ($value === null) {
            return null;
        }

        $value->setTimezone(new \DateTimeZone('UTC'));
        $dbDate = $value->format($platform->getDateTimeFormatString());

        return $dbDate;
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        if ($value === null) {
            return null;
        }

        $val = \DateTime::createFromFormat(
            $platform->getDateTimeFormatString(),
            $value,
            (self::$utc) ? self::$utc : (self::$utc = new \DateTimeZone('UTC'))
        );
        if (!$val) {
            throw ConversionException::conversionFailed($value, $this->getName());
        }
        return $val;
    }
}

问题是,当我运行app/console doctrine:migrations:diff时,即使我已经迁移了,它也始终会生成新的迁移,并且内容始终是相同的。例子:
$this->addSql('ALTER TABLE Availability CHANGE start start DATETIME NOT NULL, CHANGE end end DATETIME NOT NULL, CHANGE rrule rrule LONGTEXT DEFAULT NULL, CHANGE created created DATETIME NOT NULL, CHANGE updated updated DATETIME NOT NULL');

最佳答案

这是SteveMüller对此错误报告的回应:http://www.doctrine-project.org/jira/browse/DBAL-1085



在> = 2.3的学说中实现了某些功能

关于Symfony2 Doctrine自定义类型生成不需要的迁移,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26964367/

10-16 11:11