Missing auto_increment if custom repository annotation presented #5333

Closed
opened 2026-01-22 15:04:44 +01:00 by admin · 5 comments
Owner

Originally created by @olegsv on GitHub (Nov 24, 2016).

Originally assigned to: @ostrolucky on GitHub.

An entity class contains repository annotation, and two fields with GeneratedValue annotations, one defined as "AUTO" and another one as "GUID" .

A table corresponding to the entity is present in DB.

CREATE TABLE `my_entity` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `ident` varchar(16) DEFAULT NULL COMMENT 'GUID',
   ...

Running doctrine:schema:update in Symfony 2.8 / Doctrine 2.4.8 produces incorrect SQL in the following cases:

  1. if Repository and two GeneratedValue annotations are present, the following SQL is generated. Note the missing AUTO_INCREMENT

ALTER TABLE my_entity CHANGE id id BIGINT UNSIGNED NOT NULL;

  1. when Repository and only one GeneratedValue annotation for the primary key present, the resulting SQL is correct but does exactly nothing.

ALTER TABLE my_entity CHANGE id id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL;

  1. When Repository annotation is not present, and both fields have GeneratedValue annotation - no SQL is generated , which is a desired behaviour.
/** MyEntity
 *
 * @ORM\Table(name="my_entity")
 * @ORM\Entity(repositoryClass="My\MyBundle\Repository\MyRepository123")
 */
class MyEntity
{
    /**
     * @var int
     *
     * @ORM\Column(nullable=false, type="bigint",options={"unsigned":true,"auto_increment":true} )
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var string
     *
     * @ORM\Column(name="ident", type="string", length=16, nullable=true, options={"comment":"GUID"} )
     * @ORM\GeneratedValue(strategy="UUID")
     */
    private $ident;
    ....
Originally created by @olegsv on GitHub (Nov 24, 2016). Originally assigned to: @ostrolucky on GitHub. An entity class contains repository annotation, and two fields with GeneratedValue annotations, one defined as "AUTO" and another one as "GUID" . A table corresponding to the entity is present in DB. ``` CREATE TABLE `my_entity` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `ident` varchar(16) DEFAULT NULL COMMENT 'GUID', ... ``` Running ` doctrine:schema:update ` in Symfony 2.8 / Doctrine 2.4.8 produces incorrect SQL in the following cases: 1. if Repository and two GeneratedValue annotations are present, the following SQL is generated. Note the missing AUTO_INCREMENT `ALTER TABLE my_entity CHANGE id id BIGINT UNSIGNED NOT NULL;` 2. when Repository and only one GeneratedValue annotation for the primary key present, the resulting SQL is correct but does exactly nothing. `ALTER TABLE my_entity CHANGE id id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL;` 3. When Repository annotation is not present, and both fields have GeneratedValue annotation - no SQL is generated , which is a desired behaviour. ``` /** MyEntity * * @ORM\Table(name="my_entity") * @ORM\Entity(repositoryClass="My\MyBundle\Repository\MyRepository123") */ class MyEntity { /** * @var int * * @ORM\Column(nullable=false, type="bigint",options={"unsigned":true,"auto_increment":true} ) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="ident", type="string", length=16, nullable=true, options={"comment":"GUID"} ) * @ORM\GeneratedValue(strategy="UUID") */ private $ident; .... ```
admin added the Bug label 2026-01-22 15:04:44 +01:00
admin closed this issue 2026-01-22 15:04:45 +01:00
Author
Owner

@Ocramius commented on GitHub (Nov 25, 2016):

The ORM only supports single-column generated values. We probably need to throw an exception in the mapping load process.

@Ocramius commented on GitHub (Nov 25, 2016): The ORM only supports single-column generated values. We probably need to throw an exception in the mapping load process.
Author
Owner

@olegsv commented on GitHub (Nov 25, 2016):

In case 2 the mapper incorrectly produces similar SQL, there should be no SQL generated.

@olegsv commented on GitHub (Nov 25, 2016): In case 2 the mapper incorrectly produces similar SQL, there should be no SQL generated.
Author
Owner

@voronkovich commented on GitHub (Nov 30, 2016):

@olegsv, your example is not correct. You missed an @Id annotation in the ident property. The @GeneratedValue doesn't work without the @Id. See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#generatedvalue

@voronkovich commented on GitHub (Nov 30, 2016): @olegsv, your example is not correct. You missed an `@Id` annotation in the `ident` property. The `@GeneratedValue` doesn't work without the `@Id`. See http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#generatedvalue
Author
Owner

@olegsv commented on GitHub (Nov 30, 2016):

@voronkovich see p.2 for bug that occurs without second generated value

@olegsv commented on GitHub (Nov 30, 2016): @voronkovich see p.2 for bug that occurs without second generated value
Author
Owner

@ostrolucky commented on GitHub (Aug 6, 2018):

I gave this a go and I can't reproduce. Also, support for DB-generated UUIDs has been dropped in Doctrine/DBAL 3.0. See https://github.com/doctrine/doctrine2/pull/7330 or https://github.com/doctrine/dbal/pull/3211. Since it's very likely this issue is no longer relevant, I'm going to close this issue. If I am wrong and it's still relevant, please don't hesitate to comment here with reproducer based on master branch and we will reopen.

@ostrolucky commented on GitHub (Aug 6, 2018): I gave this a go and I can't reproduce. Also, support for DB-generated UUIDs has been dropped in Doctrine/DBAL 3.0. See https://github.com/doctrine/doctrine2/pull/7330 or https://github.com/doctrine/dbal/pull/3211. Since it's very likely this issue is no longer relevant, I'm going to close this issue. If I am wrong and it's still relevant, please don't hesitate to comment here with reproducer based on master branch and we will reopen.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5333