我有两个数据库,每个数据库都有自己的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代码优先迁移
发布评论