Unable to generate an explicit migration because the following explicit migrations are pending
After renaming the namespace of some POCO classes from Primo.LicenseManager.Models
to Primo.Licensing.DataModel
, the Entity Framework scaffolding no longer recognizes the applied migrations:
Add-Migration -Name AddInvoiceEntity -Verbose -StartUpProjectName LicensingDataModel -ProjectName LicensingDataModel
Unable to generate an explicit migration because the following explicit migrations are pending: [201310191546582_CreateTables].
Apply the pending explicit migrations before attempting to generate a new explicit migration.
In SQL Server Management Studio:
select *
from __MigrationHistory
where MigrationId = '201310191546582_CreateTables'
MigrationId: 201310191546582_CreateTables
ContextKey: Primo.LicenseManager.Models.Migrations.Configuration
Model: 0x1F8B08000000....
ProductVersion: 5.0.0.net45
The problem
In the database, the ContextKey in the __MigrationHistory table is still the old namespace: Primo.LicenseManager.Models.Migrations.Configuration
.
The solution
Update the ContextKey to the new namespace Primo.Licensing.DataModel.Migrations.Configuration
update __MigrationHistory
set ContextKey = 'Primo.Licensing.DataModel.Migrations.Configuration'
where MigrationId = '201310191546582_CreateTables'
Now this works:
Add-Migration -Name AddInvoiceEntity -Verbose -StartUpProjectName LicensingDataModel -ProjectName LicensingDataModel