Reputation: 5691
I am currently using auto-migrations with the following powershell console commands: add-migration update-database
I would like to know if there is an option to update the database automatically if the model changes (DbContext) without using the console commands.
Thanks.
Upvotes: 1
Views: 2670
Reputation: 16585
I use
public class DataContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DataContext,Configuration>());
base.OnModelCreating(modelBuilder);
}
}
This causes the database migrations to the latest version when the data context is created at code runtime.
Upvotes: 1