var configuration = new MyDbConfiguration();
configuration.TargetDatabase = new DbConnectionInfo(
"Server=MyServer;Database=MyDatabase;Trusted_Connection=True;",
"System.Data.SqlClient");
var migrator = new DbMigrator(configuration);
migrator.Update("201606030938116_InitialDatabase");
if you do not know your migration Id then you can just do:
migrator.GetDatabaseMigrations().First();
or:
migrator.GetLocalMigrations().First();
In your DbConfiguration you have to allow the auto dropping:
public class MyDbConfiguration: DbMigrationsConfiguration<MyDbContext>
{
public MyDbConfiguration()
{
this.AutomaticMigrationsEnabled = true;
this.AutomaticMigrationDataLossAllowed = true;
}
}
Update from @GTHvidsten:
Instead of getting the available migrations, you have to use this command: migrator.Update(DbMigrator.InitialDatabase);. But you also have to set the ContextKey property in MyDbConfiguration to match the one used in the Configuration object created by Package Manager. With both of these my database becomes empty.
DbContext.Database.Delete(); DbContext.Database.Initialize(true);will drop and recreate the database but it is unclear if that is what you are after.