0

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.

Crob
  • 599
  • 4
  • 26

1 Answers1

2

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
Community
  • 1
  • 1
Crob
  • 599
  • 4
  • 26