@GeneratedValue(strategy="NONE") not working on @Id #5856

Closed
opened 2026-01-22 15:20:10 +01:00 by admin · 4 comments
Owner

Originally created by @masseelch on GitHub (Jan 24, 2018).

Originally assigned to: @Ocramius on GitHub.

I am trying to have my primary column NOT getting assigned the auto_increment option by doctrine.

Following the docs i used the following approach:

 /**
     * @var integer
     *
     * @ORM\Column(name="Auftragsnummer", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    private $id;

Doctrine does ignore this and will always attempt to change the Column:
image

When trying to insert a new record, i cannot set the ID and always get

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'

since doctrine does not take my code-generated Id but tries to use the database value (which does not provide one, since auto_increment is not set).

Originally created by @masseelch on GitHub (Jan 24, 2018). Originally assigned to: @Ocramius on GitHub. I am trying to have my primary column NOT getting assigned the `auto_increment` option by doctrine. Following the docs i used the following approach: ``` /** * @var integer * * @ORM\Column(name="Auftragsnummer", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="NONE") */ private $id; ``` Doctrine does ignore this and will always attempt to change the Column: ![image](https://user-images.githubusercontent.com/12862103/35347471-838a6224-0135-11e8-8414-459ce9547458.png) When trying to insert a new record, i cannot set the ID and always get ``` SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' ``` since doctrine does not take my code-generated Id but tries to use the database value (which does not provide one, since `auto_increment` is not set).
admin added the BugIncompleteMissing Tests labels 2026-01-22 15:20:10 +01:00
admin closed this issue 2026-01-22 15:20:10 +01:00
Author
Owner

@Ocramius commented on GitHub (Jan 26, 2018):

This needs a test case to be reproduced.

@Ocramius commented on GitHub (Jan 26, 2018): This needs a test case to be reproduced.
Author
Owner

@zeleniy commented on GitHub (Sep 3, 2019):

Any success??

@zeleniy commented on GitHub (Sep 3, 2019): Any success??
Author
Owner

@Ocramius commented on GitHub (Sep 3, 2019):

Closing here: please open a new issue once a test case reproducing the issue is available.

@Ocramius commented on GitHub (Sep 3, 2019): Closing here: please open a new issue once a test case reproducing the issue is available.
Author
Owner

@Tagirijus commented on GitHub (Jun 20, 2021):

I have a similar issue, when trying to use NONE as the ID strategy. The thing on my end was: I had a loop with which I import multiple entries. And inside the loop I only did a persist() for the entity. When I change this to persist() and flush() (inside the loop) it works here.

I think that it might be that otherwise only persisted entites with manually set IDs could become a problem, when another entity during the import (without flushing in the meantime) gets persisted as well ...

Info: I am totally new to doctrine ... so maybe I do not understand something else here in general, but again: it works for me when just flushing one entity directly on my import method.

Maybe this might help somebody in the future. (-;

@Tagirijus commented on GitHub (Jun 20, 2021): I have a similar issue, when trying to use `NONE` as the ID strategy. The thing on my end was: I had a loop with which I import multiple entries. And inside the loop I only did a `persist()` for the entity. When I change this to `persist()` **and** `flush()` (inside the loop) it works here. I think that it might be that otherwise _only persisted_ entites with manually set IDs could become a problem, when another entity during the import (without flushing in the meantime) gets persisted as well ... Info: I am totally new to doctrine ... so maybe I do not understand something else here in general, but again: it works for me when just flushing one entity directly on my import method. Maybe this might help somebody in the future. (-;
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5856