Unable to generate an explicit migration - Entity Framework 6.1.3 with multiple Contexts / Configurations

asp.net asp.net-mvc entity-framework entity-framework-6

Question

I have a project that serves as an internal set of tools. Because of this I have need for multiple contexts. I have one context setup fine, then I started trying to add my second context. I learned from another SO question that you need to rename the Configuration file(s) after enabling, and then reference the new configuration file name when doing Add-Migration and Update-Database commands. I did this and ended up with the "Unable to generate an explicit migration..." which references 201605181623556_ServiceRequest which as you can see below was applied.

PM> Enable-Migrations -ContextTypeName InsideAdminContext

At this point I renamed the configuration file InsideAdminConfiguration

PM> Enable-Migrations -ContextTypeName PartFinderContext

Renamed the configuration file PartFinderconfiguration

PM> Add-Migration "ServiceRequest" -ConfigurationTypeName InsideAdminConfiguration
PM> update-database -ConfigurationTypeName InsideAdminConfiguration
Applying explicit migrations: [201605181623556_ServiceRequest].
Applying explicit migration: 201605181623556_ServiceRequest.
Running Seed method.
PM> Add-Migration "InitialMigrationForPartFinder" -ConfigurationTypeName PartFinderConfiguration
Unable to generate an explicit migration because the following explicit migrations are pending: [201605181623556_ServiceRequest]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

So far I have deleted all the migration folders, deleted the table and _MigrationHistory table and started over with the commands above, but the problem persists.

-----UPDATE-----
I reversed the order of above and created the PartFinder tables first and ended up with the same error when trying to Add-Migration on ServiceRequest.

1
0
5/18/2016 7:45:55 PM

Accepted Answer

I found the solution to this here: How do I enable EF migrations for multiple contexts to separate databases?

The part I was missing was in the answer by "bart s". The configuration files needed to have their own namespace which can be created by the Enable-Migrations -MigrationsDirectory parameter. In my situation it translates to (I have some extra parameters in here that are probably not necessary due to trying other things):

Enable-Migrations -MigrationsDirectory "Migrations\InsideAdmin" -ContextTypeName InsideIIMAK.Domain.Concrete.InsideAdminContext -StartUpProjectName InsideAdmin

Enable-Migrations -MigrationsDirectory "Migrations\PartFinder" -ContextTypeName InsideIIMAK.Domain.Concrete.PartFinderContext -StartUpProjectName InsideAdmin

Add-Migration "InitialMigrationForPartFinder" -ConfigurationTypeName InsideIIMAK.Domain.Migrations.PartFinder.PartFinderConfiguration -StartUpProjectName InsideAdmin -ConnectionStringName PartFinderContext

update-database -ConfigurationTypeName InsideIIMAK.Domain.Migrations.PartFinder.PartFinderConfiguration -StartUpProjectName InsideAdmin -ConnectionStringName PartFinderContext

Add-Migration "ServiceRequest" -ConfigurationTypeName InsideIIMAK.Domain.Migrations.InsideAdmin.InsideAdminConfiguration -StartUpProjectName InsideAdmin -ConnectionStringName InsideAdminContext

update-database -ConfigurationTypeName InsideIIMAK.Domain.Migrations.InsideAdmin.InsideAdminConfiguration -StartUpProjectName InsideAdmin -ConnectionStringName InsideAdminContext
2
5/23/2017 11:53:34 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow