@ORM\GeneratedValue(strategy="UUID") documentation should suggest column types #5438

Closed
opened 2026-01-22 15:07:47 +01:00 by admin · 6 comments
Owner

Originally created by @tarjei on GitHub (Mar 2, 2017).

Originally assigned to: @Ocramius on GitHub.

Hi, it seems to me that the correct columntype for this datatype in mysql is
@ORM\Column(type="string", length="36") but if that is the case for all databases I do not know. Would it be possible to document what the correct datatype should be?

I also found this interesting post[1] that suggests storing uuids as a binary field. Have you considered supporting that?

  1. http://mysqlserverteam.com/storing-uuid-values-in-mysql-tables/

Kind regards,
Tarjei

Originally created by @tarjei on GitHub (Mar 2, 2017). Originally assigned to: @Ocramius on GitHub. Hi, it seems to me that the correct columntype for this datatype in mysql is `@ORM\Column(type="string", length="36")` but if that is the case for all databases I do not know. Would it be possible to document what the correct datatype should be? I also found this interesting post[1] that suggests storing uuids as a binary field. Have you considered supporting that? 1. http://mysqlserverteam.com/storing-uuid-values-in-mysql-tables/ Kind regards, Tarjei
admin added the Won't FixDocumentationQuestion labels 2026-01-22 15:07:47 +01:00
admin closed this issue 2026-01-22 15:07:49 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 2, 2017):

CHAR(36) is mostly inefficient, since a UUID is just a 128 bit integer. Please refer to https://github.com/ramsey/uuid-doctrine for further guidance

@Ocramius commented on GitHub (Mar 2, 2017): `CHAR(36)` is mostly inefficient, since a UUID is just a 128 bit integer. Please refer to https://github.com/ramsey/uuid-doctrine for further guidance
Author
Owner

@tarjei commented on GitHub (Mar 2, 2017):

Ok, so the UUID method in native doctrine should not be used?

Regards

@tarjei commented on GitHub (Mar 2, 2017): Ok, so the UUID method in native doctrine should not be used? Regards
Author
Owner

@Ocramius commented on GitHub (Mar 2, 2017):

The generator strategy can be used, but it makes little sense, since UUIDs are designed so that they can be generated before DB persistence

@Ocramius commented on GitHub (Mar 2, 2017): The generator strategy can be used, but it makes little sense, since UUIDs are designed so that they can be generated before DB persistence
Author
Owner

@fabwu commented on GitHub (Oct 18, 2017):

@Ocramius I would like to change my primary keys to UUID but I'm not quite sure which doctrine type I should use. This library stores the UUID as well as CHAR(36) so I'm a bit confused.

Could you provide an example how you use UUID as primary keys in your entities?

@fabwu commented on GitHub (Oct 18, 2017): @Ocramius I would like to change my primary keys to UUID but I'm not quite sure which doctrine type I should use. [This library](https://github.com/ramsey/uuid-doctrine) stores the UUID as well as `CHAR(36)` so I'm a bit confused. Could you provide an example how you use UUID as primary keys in your entities?
Author
Owner

@AlessandroMinoccheri commented on GitHub (Oct 18, 2017):

Last time @wuethrich44 I have used this code:

/**
     * @var \Ramsey\Uuid\Uuid
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="guid")
     * @ORM\GeneratedValue(strategy="UUID")
     * @Expose()
     */
    private $id;
@AlessandroMinoccheri commented on GitHub (Oct 18, 2017): Last time @wuethrich44 I have used this code: ``` /** * @var \Ramsey\Uuid\Uuid * * @ORM\Id * @ORM\Column(name="id", type="guid") * @ORM\GeneratedValue(strategy="UUID") * @Expose() */ private $id; ```
Author
Owner

@Ocramius commented on GitHub (Oct 18, 2017):

You'd probably use the UUIDBinaryType

On 18 Oct 2017 11:56, "Fabian Wüthrich" notifications@github.com wrote:

@Ocramius https://github.com/ocramius I would like to change my primary
keys to UUID but I'm not quite sure which doctrine type I should use. This
library https://github.com/ramsey/uuid-doctrine stores the UUID as well
as CHAR(36) so I'm a bit confused.

Could you provide an example how you use UUID as primary keys in your
entities?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6312#issuecomment-337532677,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakNkqagMrX3DawkIDUE-cvtCL_P4gks5stctCgaJpZM4MQtcM
.

@Ocramius commented on GitHub (Oct 18, 2017): You'd probably use the UUIDBinaryType On 18 Oct 2017 11:56, "Fabian Wüthrich" <notifications@github.com> wrote: > @Ocramius <https://github.com/ocramius> I would like to change my primary > keys to UUID but I'm not quite sure which doctrine type I should use. This > library <https://github.com/ramsey/uuid-doctrine> stores the UUID as well > as CHAR(36) so I'm a bit confused. > > Could you provide an example how you use UUID as primary keys in your > entities? > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6312#issuecomment-337532677>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakNkqagMrX3DawkIDUE-cvtCL_P4gks5stctCgaJpZM4MQtcM> > . >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5438