Skip to content

Temporal Tables: The given key 'SqlServer:TemporalHistoryTableName' was not present in the dictionary when creating migration on entity mapped to temporal table without explicitly providing history table name #25511

Closed

Description

@maumar

Found by @benjaminsaljooghi

problem happens when trying to create migrations for model containing entity mapped to temporal table, if the history table is not explicitly specified, e.g.

modelBuilder.Entity<Student>().ToTable(tb => tb.IsTemporal());

exception:

System.Collections.Generic.KeyNotFoundException: The given key 'SqlServer:TemporalHistoryTableName' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key) in System.Private.CoreLib.dll:token 0x600675e+0x17
   at Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerAnnotationCodeGenerator.GenerateFluentApiCalls(IEntityType entityType, IDictionary`2 annotations) in Microsoft.EntityFrameworkCore.SqlServer.dll:token 0x60004c2+0x45
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypeAnnotations(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600032b+0x67d
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600031a+0x1bd
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList`1 entityTypes, IndentedStringBuilder stringBuilder) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000319+0x5f
   at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000302+0x208
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600038c+0x2b3
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x6000474+0xa5
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) in Microsoft.EntityFrameworkCore.Design.dll:token 0x60003e5+0xc
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x60006df+0x0
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() in Microsoft.EntityFrameworkCore.Design.dll:token 0x60006f3+0x0
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) in Microsoft.EntityFrameworkCore.Design.dll:token 0x600066a+0xc

Activity

  1. self-assigned this
    on Aug 13, 2021
  2. added this to the 6.0.0 milestone on Aug 13, 2021
  3. maumar commented on Aug 13, 2021

    @maumar
    ContributorAuthor

    Workaround: specify history table name

    modelBuilder.Entity<Student>().ToTable(tb => tb.IsTemporal(ttb => ttb.WithHistoryTable("StudentHistory")));
  4. added 2 commits that reference this issue on Aug 13, 2021
  5. added 3 commits that reference this issue on Aug 13, 2021
  6. modified the milestones: 6.0.0, on Aug 14, 2021
  7. modified the milestones: , 6.0.0 on Nov 8, 2021
  8. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions