I am using these packages:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
// generate id modelBuilder.HasSequence("UNIQUEIdGenerator", schema: "public") .StartsAt(2000000000) .IncrementsBy(1); // TestId is not primary key modelBuilder.Entity<ModelTest>() .Property(d => d.TestId) .HasDefaultValueSql("CONCAT('PREFIX', NEXTVAL('\"UNIQUEIdGenerator\"'))");
When I do migration it get success without any error, but when I open PGADMIN and navigate to the database and check the sequence under public schema, it doesn't show me an UNIQUEIdGenerator sequence.
**Note:- Table ModelTest was already there, when i did migration for this sequence
I was able to figure out the solution ("Work Around"). If I delete all migration files and regenerate all the migrations file and then update the db it work fine.
Step 1:- delete all the migration file + snapshot file
Step 2:- generate migration files dotnet ef migrations add
Step 3:- dotnet ef migrations script
Now if you search the output it will show you "Create Sequence" sql command, which was missing when i was trying to do with previously.