automatic-migration

EF - Default value for new column with automatic migration

我的梦境 提交于 2020-01-14 08:03:46
问题 I use EF code first and automatic migrations. I want to add a new column to my model - a boolean column to present "active" (true) or "inactive" (false). How can I add this column and set a default value ("true") for the rows that already in the DB - with automatic migrations? 回答1: Tamar, you need set default value, see next sample: namespace MigrationsDemo.Migrations { using System; using System.Data.Entity.Migrations; public partial class AddPostClass : DbMigration { public override void Up

EF - Default value for new column with automatic migration

蹲街弑〆低调 提交于 2020-01-14 08:03:14
问题 I use EF code first and automatic migrations. I want to add a new column to my model - a boolean column to present "active" (true) or "inactive" (false). How can I add this column and set a default value ("true") for the rows that already in the DB - with automatic migrations? 回答1: Tamar, you need set default value, see next sample: namespace MigrationsDemo.Migrations { using System; using System.Data.Entity.Migrations; public partial class AddPostClass : DbMigration { public override void Up