Skip to content
Advertisement

Doctrine custom types, problems updating schema

I’m having problems when I try to update my schema with doctrine “bin/console doctrine:schema:update -f”

The problem is

[DoctrineDBALException]
Unknown column type “FinancesBankInfrastructurePersistenceDoctrineBankIdType” requested. Any Doctrine type that you use has to be registered with DoctrineDBALTypesType::addType(). You can get a lis
t of all the known types with DoctrineDBALTypesType::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. U
se AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping
information.

It’s strange because when I see in my schema database I found the type in the coments, and if I delete it I can update the schema normally. I didn’t find any aditional configuration to solve this. Actually my config.yml is:

doctrine:
dbal:
    driver:   "%database_driver%"
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database_name%"
    user:     "%database_user%"
    password: "%database_password%"
    charset:  UTF8
    types:
        bank_id: FinancesBankInfrastructurePersistenceDoctrineBankIdType

schema detail

The custom type:

final class BankIdType extends UuidType
{
   protected function typeClassName(): string
   {
    return BankId::class;
   }

}

The UuidType (abstract)

abstract class UuidType extends StringType implements DoctrineCustomType
{
  abstract protected function typeClassName(): string;


  public function getName(): string
  {
    return self::customTypeName();
  }

  public static function customTypeName(): string
  {
    return static::class;
  }

  public function convertToPHPValue($value, AbstractPlatform $platform)
  {
    if(!is_null($value)){
        $className = $this->typeClassName();
        return new $className($value);
    }else{
        return $value;
    }
  }

  /** @var Uuid $value */
  public function convertToDatabaseValue($value, AbstractPlatform $platform)
  {
    if(!is_null($value)){
        return $value;
    }else{
        return $value;
    }
  }
}

The interface implemented:

interface DoctrineCustomType
{
  public static function customTypeName(): string;
}

It’s the mapping “Bank.orm.xml”

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine- 
project.org/schemas/orm/doctrine-mapping"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="FinancesBankDomainBank">
    <id name="id" type="bank_id" column="id"/>

This is driving me crazy!

Advertisement

Answer

Finally the solution was delete all the doctrine comments in mysql database and in the mapping config set the custom types as follows:

types:
  bank_id:
    class: FinancesBankInfrastructurePersistenceDoctrineBankIdType
    commented: false
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement