Take a look at this link: This gives you more freedom to activate migration for each database.
I solved this using a static connection string for a specific database inside the default constructor.
Let's say I have several databases, all based on the same scheme: myCatalog1, myCatalog2, etc. I use only the first line of the database connection in the constructor as follows:
public MyContext() : base("Data Source=.\SQLEXPRESS;Initial Catalog=myCatalog1;Integrated Security=True") {
This constructor is used only for the Add-Migration command to work and create the migration. Please note: there are no side effects for the rest of the database, and if you need another constructor to initialize the context (for purposes other than migration), it will work.
After running Add-Migration do the following:
Add-Migration -ConfigurationTypeName YourAppName.YourNamespace.Configuration "MigrationName"
I can call the following code ( taken from the link provided at the beginning ) to update the migrations for each of my databases which are based on the same scheme as myCatalog1:
YourMigrationsConfiguration cfg = new YourMigrationsConfiguration(); cfg.TargetDatabase = new DbConnectionInfo( theConnectionString, "provider" ); DbMigrator dbMigrator = new DbMigrator( cfg ); if ( dbMigrator.GetPendingMigrations().Count() > 0 ) {
ilans Jun 01 '14 at 12:26 2014-06-01 12:26
source share