Entity Framework Core 数据库自动迁移API

来源:互联网 发布:网络k歌动圈麦克风推荐 编辑:程序博客网 时间:2024/05/22 21:51

        public static async Task InitializeIdentityDatabaseAsync(IServiceProvider serviceProvider/*, bool createUsers = true*/)        {            using (var serviceScope = serviceProvider.CreateScope())            {                var db = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();                await db.Database.MigrateAsync();            }        }

如果想在启动之后,初始化数据库,关键的API是db.Database.MigrateAsync(),这个API可以根据生成的配置类,自动更新或者创建数据库的表和字段。

我在调用另外一个迁移APIdb.Database.EnsureCreatedAsync() 后,应该是我的程序问题,发现并没有成功自动更新或者创建数据库的表和字段。

Entity Framework Core 数据库Migrations命令Update更新数据库中模型

asp.net Core Entity Framework 7 数据库更新维护