I have added a new property into my existing model. It's a bool property with default value true. There are existing data in this table and I would like to set one specific row's new property to false right after creating the new field, in the Up method.
public override void Up()
{
AddColumn("dbo.RequestValidationErrors", "IsBreaking", c => c.Boolean(nullable: false));
using (Context ctx = new Context())
{
var validation = ctx.RequestValidationErrorSet.FirstOrDefault(x => x.WordCode == "RequestValidationError.MoreThanOneItemFound");
if (validation != null)
{
validation.IsBreaking = false;
ctx.SaveChanges();
}
}
}
This way EF throws an error during saying
System.InvalidOperationException: The model backing the 'DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database
Is it possible to change the database here or should I do it elsewhere?
See Question&Answers more detail:os