Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Code First Migration with Multiple Database / DbContext

I have two database each with their own dbcontext. I've setup two migration configurations. I can add a migration for the first db ust fine (Add-Migration DB1_InitialCreate -ConfigurationTypeName DB1Configuration). When I try to create an initial migration with the second db using: Add-Migration DB2_InitialCreate -ConfigurationTypeName DB2Configuration, I get the following error:

Unable to generate an explicit migration because the following explicit migrations are pending: [201205082215265_DB1_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

So I do what it says and update the database with:

Update-Database -ConfigurationTypeName DB1Configuration

Then I try to add a migration again for the second db but I keep getting the same error.

Any ideas on how to get migrations working for two databases/contexts?

like image 659
seano288 Avatar asked May 08 '12 23:05

seano288


1 Answers

I've been able to answer my own question. My two configuration classes existed in the same namespace. As soon as I separated them, everything worked.

like image 93
seano288 Avatar answered Sep 25 '22 13:09

seano288