-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeneratedValue strategy AUTO should use IDENTITY on PostgreSQL #5614
Comments
AFAIK this would only work with SERIAL fields (fields with default value being |
Hmm, I also stumpled upon this issue.
So the sequence is not assigned as default value. However, when adding entitities, the id is incremented. I don't understand why. |
@flaushi Because of doctrine getting ID from the sequence and add to the INSERT statement. |
Starting with the PostgreSQL 10 more prefered way for using autoincrement is syntax GENERATED AS IDENTITY that is very similar to mysql AUTO_INCREMENT It would be great to support by doctrine this features
http://www.postgresqltutorial.com/postgresql-identity-column/ |
In light of the changes introduced in PostgreSQL 10 (as mentioned by @breitsmiley) this should be reviewed. At least make the default when Postgres version equals 10 |
Any update on this one? I'm starting a new migration and it would be much welcomed as the existing database uses this. If the team is open to merging a contributed PR, I will take a stab at it. |
I think until this is supported, using the |
hi @greg0ire As far as I can tell
And Doctrine uses sequences anyway:
So the documentation (https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/basic-mapping.html#identifier-generation-strategies) seems to be wrong, too, in this case (It says that PostgreSQL uses |
🤔 indeed, dbal/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php Lines 191 to 194 in a55eb48
I have some faint memories of using |
Yes it's clearly a problem, and the documentation is misleading. For those that pull some hair over this, I use custom migrations with stuff like that to achieve my goals (in a Symfony app) and I don't use auto-generated migrations:
I still leave |
Hi @beberlei, any update on this ? As explicited above, either the documentation is wrong and Thanks a lot ! |
is it dbal/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php Lines 985 to 995 in a55eb48
by something like
? |
@allan-simon your proposal is something we probably should (and will?) do in the next major version of the DBAL, but in the current one, the expected result is |
@greg0ire , ok if it's planned on doctrine's core team side , then I should wait :) |
Related: #4744 |
ok it seems it will land with 4.0.x of dbal https://github.com/doctrine/dbal/pull/5396/files |
🤔 I'm moving this issue to |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
As per http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies - AUTO uses SEQUENCE by default on PostgreSQL. This seems sub-optimal as it forces INSERT queries to provide the id explicitly using
nextval('sequence_name')
which is not easy to do in ORM queries, and requires that you know the sequence name. On the other hand if it's set to IDENTITY it works better as it does it like MySQL's AUTO_INCREMENT, you can just omit the id field entirely.As doing this would cause schema changes I can imagine it won't be fixed in a minor release, but should be considered for v3 I think.
The text was updated successfully, but these errors were encountered: