Issue still exists with 32-bit identity seed values in migrations
See original GitHub issueI’ve been upgrading our solution from .NET 5 to .NET 6. After upgrading all package to the latest RC1 versions, our applications migrations no longer function. These migrations do work fine under .NET 5.
This is the exception being produced when running the application (migrations are applied during app startup during local development):
[10:13:10 INF] Applying migration '20210729135458_Initial'.
[10:13:10 FTL] Application startup exception
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Nullable`1[System.Int64]'.
at Microsoft.EntityFrameworkCore.SqlServerPropertyExtensions.GetIdentitySeed(IReadOnlyProperty property, StoreObjectIdentifier& storeObject)
at Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal.SqlServerAnnotationProvider.For(IColumn column, Boolean designTime)+MoveNext()
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(AnnotatableBase annotatable, IEnumerable`1 annotations)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(IEnumerable`1 annotations)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, Boolean designTime)
at Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, Boolean designTime)
at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.InitializeModel(IModel model, Boolean designTime, Boolean prevalidation)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.<>c.<Initialize>b__4_0(ValueTuple`4 args)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.<>c__30`2.<GetOrAddRuntimeAnnotationValue>b__30_0(String n, ValueTuple`3 t)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.GetOrAddRuntimeAnnotationValue[TValue,TArg](String name, Func`2 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger`1 validationLogger)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.FinalizeModel(IModel model)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass16_2.<GetMigrationCommandLists>b__2()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
at Deployed.Core.Api.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, CoreContext context) in C:\Git\Deployed\Platform\src\Core\src\Api\Startup.cs:line 108
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.WebTools.BrowserLink.Net.HostingStartup.<>c__DisplayClass1_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Watch.BrowserRefresh.HostingStartup.<>c__DisplayClass1_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Include provider and version information
EF Core version: 6.0.0-rc.1.21452.10 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 6.0 RC 1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
As there is no unsigned int in SQL Server doesn't an ...
I just had a showerthought that the default Identity Seed is 1. I have some tables that I know will grow to the...
Read more >How to set Identity Seed value in code-first?
Currently we can set it to auto increment via the EntityTypeBuilder during migrations using: entityBuilder.Property(e => e.PropertyName).
Read more >Why did my IDENTITY seed change?
My IDENTITY value is less than the current column value. A rollback that doesn't reseed would leave the IDENTITY value higher than the...
Read more >SQl Server to Aurora PostgreSQL Migration Playbook - Awsstatic
Migrate to: Aurora PostgreSQL Transparent Data Encryption ... Create a table with column constraints and an identity. ... 32-bit currency amount.
Read more >Using MongoDB as a source for AWS DMS
Each document has a unique ID. AWS DMS supports two migration modes when using MongoDB as a source, Document mode or Table mode....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This does seem to be the same as #25589, but the fix there is in the snapshot model processor, which only seems to get invoked when scaffolding or removing a migration; when applying migrations we don’t go through the processor.
@AndriySvyryd I’ve submitted #26066 which adds the proper int->long conversions in the metadata API and the annotation code generator, plus a test - take a look.
@chrissainty you can indeed work around this by editing your model snapshots and adding the L to make the value a long.
Thanks, this repros for me now, will investigate 👍