Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 2.0.0-BETA4
-
Fix Version/s: None
-
Component/s: Schema Managers
-
Labels:None
-
Environment:Ubuntu 10.10, MySQL 5.1.49, PHP 5.3.3
Description
I defined a custom type for DBAL and used it in an entity annotation. Every time I call doctrine orm:schema-tool:update, even when no changes are been made to the code, DBAL thinks the schema has changed and needs an update. The type declaration is done in cli-config.php, when creating the EntityManager.
See the code and output below:
Project/CustomType.php
namespace Project;
use \Doctrine\DBAL\Platforms\AbstractPlatform,
\Doctrine\DBAL\Types\Type;
class CustomType extends Type
{
const TYPE = 'custom';
public function getSqlDeclaration(array $fieldDeclaration,
AbstractPlatform $platform)
{
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}
public function getName()
{
return self::TYPE;
}
}
Project/Entity.php
/**
* @entity
*/
namespace Project;
class Entity
{
/**
* @id
* @column(type="integer")
*/
private $id;
/**
* @column(type="custom")
*/
private $custom;
}
cli-config.php
$cache = new \Doctrine\Common\Cache\ApcCache; $config = new \Doctrine\ORM\Configuration; $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/Project'); $config->setMetadataDriverImpl($driverImpl); $config->setProxyDir(APPLICATION_PATH . '/Proxies'); $config->setProxyNamespace('Proxies'); $config->setAutoGenerateProxyClasses(true); $connectionOptions = array( 'driver' => 'pdo_mysql', 'dbname' => 'project', 'user' => '#user#', 'password' => '#password#', 'host' => 'localhost', ); \Doctrine\DBAL\Types\Type::addType('custom', 'Project\CustomType'); $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), ));
Console Output
#:~ doctrine orm:schema-tool:create --dump-sql CREATE TABLE Entity (id INT NOT NULL, custom VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB #:~ doctrine orm:schema-tool:create Creating database schema... Database schema created successfully! #:~ doctrine orm:schema-tool:update --dump-sql ALTER TABLE Entity CHANGE custom custom VARCHAR(255) NOT NULL #:~ doctrine orm:schema-tool:update --force Updating database schema... Database schema updated successfully! #:~ doctrine orm:schema-tool:update --dump-sql ALTER TABLE Entity CHANGE custom custom VARCHAR(255) NOT NULL
Yes, it thinks its a varchar and wants to update that definition. This is a duplicate of
DBAL-42