EF Core 在迁移过程中锁定数据库 [英] EF Core lock the database during migration

查看:34
本文介绍了EF Core 在迁移过程中锁定数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Database.Migrate()运行迁移时,是否可以从任何其他连接锁定数据库?

Is it possible lock the database from any other connections when running the migrations through Database.Migrate()?

我们有多个服务实例运行相同的代码(在 AWS Lambda 上),并在启动时进行迁移.现在,当我们想要应用一些迁移时,我们必须手动确保只有一个实例正在运行,否则他们都可以尝试这样做并破坏事情.

We have multiple service instances running the same code (on AWS Lambda), and do the migrations on startup. Now we have to manually make sure that only one instance is running when we want to apply some migrations, otherwise they can both try to do it and break things bad.

是否有数据库级别的解决方案?

Is there a database level solution to this?

ef-core 2.1

ef-core 2.1

推荐答案

不太确定这是否是您要找的,但如果您愿意将普通的 SQL 添加到您的迁移中,您可以将数据库设置为单用户模式:阅读更多

Not really sure if this is what you are looking for, but if you are willing to add plain SQL to your migration you could set database to single user mode: Read more

这篇关于EF Core 在迁移过程中锁定数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆