具有多个数据库/ DbContext的EF代码优先迁移 [英] EF Code First Migration with Multiple Database / DbContext

查看:64
本文介绍了具有多个数据库/ DbContext的EF代码优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据库,每个数据库都有自己的dbcontext。我已经设置了两个迁移配置。我可以为第一个数据库添加迁移( Add-Migration DB1_InitialCreate -ConfigurationTypeName DB1Configuration )。当我尝试使用以下命令与第二个数据库创建初始迁移时: Add-Migration DB2_InitialCreate -ConfigurationTypeName DB2Configuration ,出现以下错误:

I have two database each with their own dbcontext. I've setup two migration configurations. I can add a migration for the first db ust fine (Add-Migration DB1_InitialCreate -ConfigurationTypeName DB1Configuration). When I try to create an initial migration with the second db using: Add-Migration DB2_InitialCreate -ConfigurationTypeName DB2Configuration, I get the following error:


由于以下显式迁移未决,因此无法生成显式迁移:[201205082215265_DB1_InitialCreate]。在尝试生成新的显式迁移之前,请先应用待处理的显式迁移。

Unable to generate an explicit migration because the following explicit migrations are pending: [201205082215265_DB1_InitialCreate]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

所以我照着说了做,并用以下内容更新数据库:

So I do what it says and update the database with:

Update-Database -ConfigurationTypeName DB1Configuration

然后我尝试再次为第二个数据库添加迁移,但是我仍然遇到相同的错误。

Then I try to add a migration again for the second db but I keep getting the same error.

有关如何进行迁移的任何想法为两个数据库/上下文工作?

Any ideas on how to get migrations working for two databases/contexts?

推荐答案

我已经能够回答自己的问题。我的两个配置类存在于同一名称空间中。我一分开它们,一切就正常了。

I've been able to answer my own question. My two configuration classes existed in the same namespace. As soon as I separated them, everything worked.

这篇关于具有多个数据库/ DbContext的EF代码优先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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