I have created an app using the lastest ASP.NET5 MVC 6 Entity Framework 7 and setup migrations using
dnx . ef migration add Initial
dnx . ef migration apply
This works but when I make a change to the model the database is not updated. I would like to have the database automatically update after a model change when I run the program.
My research only points me to old information that doesn't seem to be appropriate to Entity Framework 7.
My current code:
public ApplicationDbContext(): base()
{
if (!_created)
{
Database.AsRelational().ApplyMigrations();
_created = true;
}
}
Can someone point me in the right direction?
I believe it use to work something like this:
Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());
You must manually run migrations with EF7 from command line, or call Database.Migrate from code, there is nothing automagic in EF7 (a deliberate decision) and after you change your model, create a new migration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With