EF修改表结构,不删除数据

时间:2022-02-26 22:20:38
1 , Global.asax.cs添加如下代码:Database.SetInitializer<EFDbContext>(null);
2 ,修改表结构 ,
3 ,修改实体类和表结构同步
4 ,如果第一次数据迁移 执行以下代码:

Enable-Migrations -ProjectName SportStore.Domain -ContextTypeName SportStore.Domain.Entities.Concrete.EFDbContext

add-migration -ProjectName SportStore.Domain Initial

update-database -ProjectName SportStore.Domain

 

5,如果不是第一次,执行代码:

Enable-Migrations -Force -ProjectName SportStore.Domain -ContextTypeName SportStore.Domain.Entities.Concrete.EFDbContext
add-migration -Force -ProjectName SportStore.Domain Initial
update-database –Verbose -ProjectName SportStore.Domain