Open Satancito opened 3 years ago
There is currently no official way yet for Pomelo to set an initial auto increment value. However, this feature will be added for 6.0.0.
In the meantime, I can provide a temporary workaround if you need one.
My short solution for now is to add manually the following line in migration for each entity.
migrationBuilder.Sql("ALTER TABLE `Identity.User` AUTO_INCREMENT = 10000;");
But this is not automatic as in the case of the command dotnet ef migrations add.
If it is not much complexity that this is added in version 5.0.0 I would be grateful.
Adding additional annotation support for method HasAnnotation in PropertyBuilder, TableBuilder(Migration class) or EntityTypeBuilder. It would be a great help.
e.g.
propertyBuilderInstance.Annotation("MySql:AutoIncrement", "10000");
tableBuilderInstance.Annotation("MySql:AutoIncrement", "10000");
EntityTypeBuilderInstance.Annotation("MySql:AutoIncrement", "10000");
If it is not much complexity that this is added in version 5.0.0 I would be grateful.
Unfortunately, we will not add this to 5.0, because it is too invasive.
We could consider backporting the recent table options support (#1463), because we can add it without any side effects.
You would then be able to call entity.HasTableOption("AUTO_INCREMENT", "10000")
.
When you upgrade to 6.0, you would need to replace it with the new proper way we will introduce (similar to the other providers).
On the other hand, since you only have to add your migrationBuilder.Sql()
script once for every table that needs a special auto increment seed (and only for a single migration), it might be good enough for you to do this once and just wait for the 6.0 implementation (we will likely implement it for 6.0.0-preview.6
).
(If you definitely want to use a annotation for it though, I can post you some code, so you can implement it as a custom annotation that only works for you.)
Thanks. I need the example.
@Satancito Here is the code:
It generates the following SQL when run:
It should work with migrations as well.
Nice. Elegant solution. Thanks a lot @lauxjpn .
There is currently no official way yet for Pomelo to set an initial auto increment value. However, this feature will be added for 6.0.0.
In the meantime, I can provide a temporary workaround if you need one.
I came across this comment and I was wondering of this was indeed released in version 6, because I can't seem to find any implementation for it.
@cguijt No, we did not implement this yet. Let's reopen this issue, so that we don't forget about it for 7.0.
Hi @lauxjpn, I am using the 7.0.0 version of EntityFrameworkCore.MySql but seems it is still not implemented, I will be very thankful If I get any update on that.
@Satancito Here is the code:
Program.cs It generates the following SQL when run:
Generated SQL It should work with migrations as well.
@lauxjpn would you happen to have an updated example? I would like to set the default value without creating a custom migration and this does not appear to work with the latest versions of EF / Pomelo.
How can set AUTO_INCREMENT initial value for primary key using Pomelo.EntityFrameworkCore.MySql?.
like this https://stackoverflow.com/questions/1485668/how-to-set-initial-value-and-auto-increment-in-mysql
The issue
I need to create a table with bigint primary key starting at 10000.
Generated script
My C# static method for Identity column
Further technical details
MySQL version: 8.x.x Operating system: Windows Pomelo.EntityFrameworkCore.MySql version: 5.0.0 Microsoft.AspNetCore.App version: 5.0.0