The tests "ToLatestVersion_use_connection_name_from_config_file" and "MigrateDatabaseToLatestVersion_invokes_migrations_pipeline_to_latest_version" are failing on my machine after pulling the ContextKey change. It seems that the history table has the ContextKey column but the model it contains does not have the ContextKey column, so we’re trying to add it but then this fails. I haven’t been able to figure out how we get in this state and it’s possible if I delete the test database and re-run that it will work, but I’d rather understand how it is we can get into this state so I have disabled the test and filed this bug.
Exception:
Test 'ProductivityApiUnitTests.DatabaseInitializationTests.MigrateDatabaseToLatestVersion_use_connection_name_from_config_file' failed:
System.Data.SqlClient.SqlException : Column names in each table must be unique. Column name 'ContextKey' in table 'dbo.__MigrationHistory' is specified more than once.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Migrations\DbMigrator.cs(817,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
Migrations\Infrastructure\MigratorBase.cs(159,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
Migrations\DbMigrator.cs(791,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
Migrations\Infrastructure\MigratorBase.cs(151,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
Migrations\DbMigrator.cs(773,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
Migrations\DbMigrator.cs(681,0): at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
Migrations\Infrastructure\MigratorBase.cs(117,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
Migrations\DbMigrator.cs(478,0): at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
Migrations\Infrastructure\MigratorBase.cs(167,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
Migrations\DbMigrator.cs(413,0): at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
Migrations\Infrastructure\MigratorBase.cs(72,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
MigrateDatabaseToLatestVersion`.cs(53,0): at System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context)
DatabaseInitializationTests.cs(258,0): at ProductivityApiUnitTests.DatabaseInitializationTests.MigrateDatabaseToLatestVersion_use_connection_name_from_config_file()
Model from history table:
<Edmx Version="3.0" xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
<Runtime>
<ConceptualModels>
<Schema Namespace="ProductivityApiUnitTests" Alias="Self" p4:UseStrongSpatialTypes="false" xmlns:p4="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="EmptyContext" />
<EntityType Name="HistoryRow" p4:IsSystem="true">
<Key>
<PropertyRef Name="MigrationId" />
</Key>
<Property Name="MigrationId" Type="String" FixedLength="false" MaxLength="255" Unicode="true" Nullable="false" />
<Property Name="Model" Type="Binary" FixedLength="false" MaxLength="Max" Nullable="false" />
<Property Name="ProductVersion" Type="String" FixedLength="false" MaxLength="32" Unicode="true" Nullable="false" />
</EntityType>
</Schema>
</ConceptualModels>
<Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="CodeFirstDatabase" CdmEntityContainer="EmptyContext">
<EntitySetMapping Name="History" p6:IsSystem="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntityTypeMapping TypeName="System.Data.Entity.Migrations.History.HistoryRow">
<MappingFragment StoreEntitySet="HistoryRow">
<ScalarProperty Name="MigrationId" ColumnName="MigrationId" />
<ScalarProperty Name="Model" ColumnName="Model" />
<ScalarProperty Name="ProductVersion" ColumnName="ProductVersion" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</Mappings>
<StorageModels>
<Schema Namespace="CodeFirstDatabaseSchema" Provider="System.Data.SqlClient" ProviderManifestToken="2008" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityContainer Name="CodeFirstDatabase">
<EntitySet Name="HistoryRow" EntityType="Self.HistoryRow" Schema="dbo" Table="__MigrationHistory" p6:IsSystem="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
</EntityContainer>
<EntityType Name="HistoryRow" p5:IsSystem="true" xmlns:p5="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<Key>
<PropertyRef Name="MigrationId" />
</Key>
<Property Name="MigrationId" Type="nvarchar" MaxLength="255" Nullable="false" />
<Property Name="Model" Type="varbinary(max)" Nullable="false" />
<Property Name="ProductVersion" Type="nvarchar" MaxLength="32" Nullable="false" />
</EntityType>
</Schema>
</StorageModels>
</Runtime>
<Designer>
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="False" />
<DesignerProperty Name="CodeGenerationStrategy" Value="None" />
<DesignerProperty Name="ProcessDependentTemplatesOnSave" Value="False" />
</DesignerInfoPropertySet>
</Options>
<Diagrams />
</Designer>
</Edmx>
Comments: Scratch that - Looks like it might just be an upgrade scenario.
Exception:
Test 'ProductivityApiUnitTests.DatabaseInitializationTests.MigrateDatabaseToLatestVersion_use_connection_name_from_config_file' failed:
System.Data.SqlClient.SqlException : Column names in each table must be unique. Column name 'ContextKey' in table 'dbo.__MigrationHistory' is specified more than once.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Migrations\DbMigrator.cs(817,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
Migrations\Infrastructure\MigratorBase.cs(159,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
Migrations\DbMigrator.cs(791,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
Migrations\Infrastructure\MigratorBase.cs(151,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
Migrations\DbMigrator.cs(773,0): at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
Migrations\DbMigrator.cs(681,0): at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
Migrations\Infrastructure\MigratorBase.cs(117,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
Migrations\DbMigrator.cs(478,0): at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
Migrations\Infrastructure\MigratorBase.cs(167,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
Migrations\DbMigrator.cs(413,0): at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
Migrations\Infrastructure\MigratorBase.cs(72,0): at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
MigrateDatabaseToLatestVersion`.cs(53,0): at System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context)
DatabaseInitializationTests.cs(258,0): at ProductivityApiUnitTests.DatabaseInitializationTests.MigrateDatabaseToLatestVersion_use_connection_name_from_config_file()
Model from history table:
<Edmx Version="3.0" xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
<Runtime>
<ConceptualModels>
<Schema Namespace="ProductivityApiUnitTests" Alias="Self" p4:UseStrongSpatialTypes="false" xmlns:p4="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="EmptyContext" />
<EntityType Name="HistoryRow" p4:IsSystem="true">
<Key>
<PropertyRef Name="MigrationId" />
</Key>
<Property Name="MigrationId" Type="String" FixedLength="false" MaxLength="255" Unicode="true" Nullable="false" />
<Property Name="Model" Type="Binary" FixedLength="false" MaxLength="Max" Nullable="false" />
<Property Name="ProductVersion" Type="String" FixedLength="false" MaxLength="32" Unicode="true" Nullable="false" />
</EntityType>
</Schema>
</ConceptualModels>
<Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="CodeFirstDatabase" CdmEntityContainer="EmptyContext">
<EntitySetMapping Name="History" p6:IsSystem="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntityTypeMapping TypeName="System.Data.Entity.Migrations.History.HistoryRow">
<MappingFragment StoreEntitySet="HistoryRow">
<ScalarProperty Name="MigrationId" ColumnName="MigrationId" />
<ScalarProperty Name="Model" ColumnName="Model" />
<ScalarProperty Name="ProductVersion" ColumnName="ProductVersion" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</Mappings>
<StorageModels>
<Schema Namespace="CodeFirstDatabaseSchema" Provider="System.Data.SqlClient" ProviderManifestToken="2008" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityContainer Name="CodeFirstDatabase">
<EntitySet Name="HistoryRow" EntityType="Self.HistoryRow" Schema="dbo" Table="__MigrationHistory" p6:IsSystem="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
</EntityContainer>
<EntityType Name="HistoryRow" p5:IsSystem="true" xmlns:p5="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<Key>
<PropertyRef Name="MigrationId" />
</Key>
<Property Name="MigrationId" Type="nvarchar" MaxLength="255" Nullable="false" />
<Property Name="Model" Type="varbinary(max)" Nullable="false" />
<Property Name="ProductVersion" Type="nvarchar" MaxLength="32" Nullable="false" />
</EntityType>
</Schema>
</StorageModels>
</Runtime>
<Designer>
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="False" />
<DesignerProperty Name="CodeGenerationStrategy" Value="None" />
<DesignerProperty Name="ProcessDependentTemplatesOnSave" Value="False" />
</DesignerInfoPropertySet>
</Options>
<Diagrams />
</Designer>
</Edmx>
Comments: Scratch that - Looks like it might just be an upgrade scenario.