【问题标题】:Update Production Database to With Migration Files使用迁移文件更新生产数据库
【发布时间】:2022-01-17 16:16:03
【问题描述】:

我在我的项目中使用代码优先数据库方法。我想反映对生产服务器的更改。 我尝试使用启动文件中的以下代码和平来实现此目标,但它不起作用:

using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService<BaseDBContext>();
                var GetPendingMigrations = context.Database.GetPendingMigrations(); // Used to check data 
                var GetAppliedMigrarions = context.Database.GetAppliedMigrations();// Used to check data 
                
                context.Database.Migrate();
            }

如何使用实体框架核心中的最新迁移文件更新生产数据库

【问题讨论】:

    标签: c# entity-framework-core entity-framework-migrations


    【解决方案1】:

    如果数据库不存在,MigrateAsync() 将创建它,然后应用迁移。

    检查是否有任何待处理的迁移: https://makolyte.com/ef-core-apply-migrations-programmatically/

    【讨论】:

      猜你喜欢
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多