Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 无法生成具有多个上下文/配置的显式迁移实体框架6.1.3_Asp.net_Asp.net Mvc_Entity Framework_Entity Framework 6 - Fatal编程技术网

Asp.net 无法生成具有多个上下文/配置的显式迁移实体框架6.1.3

Asp.net 无法生成具有多个上下文/配置的显式迁移实体框架6.1.3,asp.net,asp.net-mvc,entity-framework,entity-framework-6,Asp.net,Asp.net Mvc,Entity Framework,Entity Framework 6,我有一个作为内部工具集的项目。因此,我需要多个上下文。我有一个上下文设置很好,然后我开始尝试添加第二个上下文。我从另一个SO问题中了解到,启用后需要重命名配置文件,然后在执行添加迁移和更新数据库命令时引用新的配置文件名。我这样做了,结果是“无法生成显式迁移…”,它引用了201605181623556_ServiceRequest,正如您在下面看到的,它被应用了 PM> Enable-Migrations -ContextTypeName InsideAdminContext 此时,我将配

我有一个作为内部工具集的项目。因此,我需要多个上下文。我有一个上下文设置很好,然后我开始尝试添加第二个上下文。我从另一个SO问题中了解到,启用后需要重命名配置文件,然后在执行添加迁移和更新数据库命令时引用新的配置文件名。我这样做了,结果是“无法生成显式迁移…”,它引用了201605181623556_ServiceRequest,正如您在下面看到的,它被应用了

PM> Enable-Migrations -ContextTypeName InsideAdminContext
此时,我将配置文件重命名为InsidedMinConfiguration

PM> Enable-Migrations -ContextTypeName PartFinderContext
PM> Add-Migration "ServiceRequest" -ConfigurationTypeName InsideAdminConfiguration
PM> update-database -ConfigurationTypeName InsideAdminConfiguration
Applying explicit migrations: [201605181623556_ServiceRequest].
Applying explicit migration: 201605181623556_ServiceRequest.
Running Seed method.
PM> Add-Migration "InitialMigrationForPartFinder" -ConfigurationTypeName PartFinderConfiguration
Unable to generate an explicit migration because the following explicit migrations are pending: [201605181623556_ServiceRequest]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
已重命名配置文件PartFinderconfiguration

PM> Enable-Migrations -ContextTypeName PartFinderContext
PM> Add-Migration "ServiceRequest" -ConfigurationTypeName InsideAdminConfiguration
PM> update-database -ConfigurationTypeName InsideAdminConfiguration
Applying explicit migrations: [201605181623556_ServiceRequest].
Applying explicit migration: 201605181623556_ServiceRequest.
Running Seed method.
PM> Add-Migration "InitialMigrationForPartFinder" -ConfigurationTypeName PartFinderConfiguration
Unable to generate an explicit migration because the following explicit migrations are pending: [201605181623556_ServiceRequest]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
到目前为止,我已经删除了所有迁移文件夹,删除了表和_MigrationHistory表,并使用上面的命令重新开始,但问题仍然存在

-----更新------

我颠倒了上面的顺序,首先创建了PartFinder表,最后在尝试添加ServiceRequest上的迁移时出现了相同的错误。

我在这里找到了解决方案:

我遗漏的那部分是“巴特s”的回答。配置文件需要有自己的名称空间,可以通过Enable Migrations-MigrationsDirectory参数创建名称空间。在我的情况下,它会转化为(我这里有一些额外的参数,由于尝试了其他事情,这些参数可能是不必要的):


我在这里找到了解决方案:

我遗漏的那部分是“巴特s”的回答。配置文件需要有自己的名称空间,可以通过Enable Migrations-MigrationsDirectory参数创建名称空间。在我的情况下,它会转化为(我这里有一些额外的参数,由于尝试了其他事情,这些参数可能是不必要的):