好吧,这对我来说是个谜。我在数据库中使用代码优先迁移已有一段时间了。但是从一个月左右开始,还原数据库时我无法运行update-database,因为迁移似乎跳过了很多迁移。
如果我查看__MigrationHistory表,则最后一个条目是一个特定的脚本,如果我运行update-database,而不是在该最后一个脚本之后开始,它将跳过22个脚本并尝试运行最后5个脚本。
项目的命名空间未更改...如果我在迁移历史记录表中查找,则ContextKey相同,productversion也是如此...
我什至试图用update-database命令删除数据库并创建一个新的数据库,但它会跳过除最后5个脚本之外的所有脚本!
我尝试重建,清理,重置IIS,更改连接字符串...我只是迷路了。
这是__migrationHistory表的内容:
MigrationId ContextKey Model ProductVersion
--------------------------------------------------------------------- ---------------------------------------------------- ------- --------------------------------
201802201653309_InitialCreate Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201802201720386_Test Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201802201734295_ContactEmployeeNumber Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201802201826462_MoveEmployeeDetailsToUser Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803082030424_ServiceUnitDisplayTypeTruckCode_AutomaticMigration Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803082030425_ServiceUnitDisplayTypeTruckCode Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803091645366_ServiceUnitActiveUI Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803092009258_ResinstateDefaultsForDates Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803131414260_BillingLotRemoveName Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803191647376_ServiceUnitAdjustments Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201803221302104_WorkShiftAddServiceUnit Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201804261628525_UpdateImageTableFollowUp Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201804261655433_UpdateImageTableFollowUpAgain Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201804261958540_AddFileDefinitionDocument Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805021302284_ProductDocumentCascadeDelete Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805141618022_AdjustSyncTableForInit Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805142001403_WOHDispatchCancelled Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805161638547_AddFileHashInFileDef Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805171405415_AdjustSPSyncDetails Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805171829504_AddWohScheduledEndDate Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805251331046_RenameWohToSR Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805251400023_UpdateTrigger Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805281937432_MoveWOBIntoServiceRequest Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
201805291216084_WOBTableRemoved Teknome.XS.Infrastructure.Migrations.Configuration <binary> 6.2.0-61023
这是解决方案中脚本屏幕快照的链接,所选脚本是被跳过的脚本,在更新数据库上执行的第一个脚本是201902061351542_ClientSpEndDateNullable。