Reputation: 976
Let's say I have a simple site with one context
public class DataContext : DbContext
{
public DbSet<Stuff> Stuff { get; set; }
}
and one model
public class Stuff
{
public int ID {get;set; }
public string Name {get;set;}
}
And I'm using code-first EF model, and I hit update-database and it creates my tables and then I publish my site. Everything is great. However, then I decide I want to add a property to my model
public class Stuff
{
public int ID {get;set; }
public string Name {get;set;}
public int StuffType {get;set;}
}
And now I hit update-database and it updates the database with the new property, but the published site is now broken because its model is out of date with the database model.
Other than frantically trying to republish the site before anyone notices, is there any other way work with code-first migrations without breaking a published site?
Do I need to have two databases? If so, how do I then maintain the models between the two? This is further compounded by the fact that I usually have (at least) two git branches, and the published site is running the code from the master branch and I'm working on a develop branch - which is where I'd be modifying my models.
What is the usual workflow for avoiding these sorts of problems?
Upvotes: 2
Views: 209
Reputation: 3860
Try disabling the database initializer for your DataContext. See this answer Entity Framework 6.1.1 disable model compatibility checking
Upvotes: 1