Using Uuid type in entity #6619

Open
opened 2026-01-22 15:35:49 +01:00 by admin · 1 comment
Owner

Originally created by @shubaivan on GitHub (Feb 2, 2021).

I using

"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
"symfony/framework-bundle": "5.2.*",

and my goal provide uuid property for my table. I followed to documentation and faced with this error when executed doctrine migration diff

  Unknown column type "uuid" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Do  
  ctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use Abstrac  
  tPlatform#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.  

then I checked available types

\Doctrine\DBAL\Types\Type::getTypesMap();

all types belongs to dbal extension

then I found uuid type class in doctrine-bundle and added in to doctrine conf

doctrine:
  dbal:
    default_connection: default
    types:
      uuid: Symfony\Bridge\Doctrine\Types\UuidType

I guess it's not obviously, maybe this part should be in symfony doc.

my question where is guarantee which uuid will be uniq, I mean maybe should be some method for check if current uuid present in table then need to generate new and check again ?

I did not found somethng about that in

\Symfony\Bridge\Doctrine\Types\AbstractUidType::convertToDatabaseValue

this is migration sql what I got from migration diff

    $this->addSql('CREATE TABLE unique_identifiers (id INT NOT NULL, request_hash UUID NOT NULL, PRIMARY KEY(id))');
    $this->addSql('COMMENT ON COLUMN unique_identifiers.request_hash IS \'(DC2Type:uuid)\'');
Originally created by @shubaivan on GitHub (Feb 2, 2021). I using "doctrine/annotations": "^1.0", "doctrine/doctrine-bundle": "^2.2", "doctrine/doctrine-migrations-bundle": "^3.0", "doctrine/orm": "^2.8", "symfony/framework-bundle": "5.2.*", and my goal provide uuid property for my table. I followed to [documentation][1] and faced with this error when executed doctrine migration diff Unknown column type "uuid" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Do ctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use Abstrac tPlatform#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. then I checked available types \Doctrine\DBAL\Types\Type::getTypesMap(); all types belongs to dbal extension then I found uuid type class in doctrine-bundle and added in to doctrine conf doctrine: dbal: default_connection: default types: uuid: Symfony\Bridge\Doctrine\Types\UuidType I guess it's not obviously, maybe this part should be in symfony doc. my question where is guarantee which uuid will be uniq, I mean maybe should be some method for check if current uuid present in table then need to generate new and check again ? I did not found somethng about that in \Symfony\Bridge\Doctrine\Types\AbstractUidType::convertToDatabaseValue this is migration sql what I got from migration diff $this->addSql('CREATE TABLE unique_identifiers (id INT NOT NULL, request_hash UUID NOT NULL, PRIMARY KEY(id))'); $this->addSql('COMMENT ON COLUMN unique_identifiers.request_hash IS \'(DC2Type:uuid)\''); [1]: https://symfony.com/doc/current/components/uid.html#storing-uuids-in-databases
Author
Owner

@BackEndTea commented on GitHub (Mar 19, 2021):

The chance of a uuid being duplicate is there, but it is extremely small.

This stackoverflow question (and answer) may provide some insight: https://stackoverflow.com/questions/1155008/how-unique-is-uuid

@BackEndTea commented on GitHub (Mar 19, 2021): The chance of a uuid being duplicate is there, but it is **extremely** small. This stackoverflow question (and answer) may provide some insight: https://stackoverflow.com/questions/1155008/how-unique-is-uuid
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6619