我有两个上下文和一个数据库。
当我尝试添加数据库迁移(add-migrations)时,出现了这个错误。
我已经将EF更新到6.2。
我检查了configuration.cs文件,它正在使用
internal sealed class Configuration : DbMigrationsConfiguration<MSiH.CigaretteContext>
PM> add-migration -configuration MSiH.DataAccess.CigaretteContext -Verbose 命令管道的位置1处的cmdlet Add-Migration 为以下参数提供值: 名称: Initals 使用启动项目'GridAndMap'。 使用NuGet项目'GridAndMap'。
说明:以上命令是添加迁移的,参数包括配置、名称等。启动项目和NuGet项目也需要指定。System.Data.Entity.Migrations.Infrastructure.MigrationsException: The type
'MSiH.CigaretteContext' does not inherit from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
Migrations configuration types must extend from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T]
(Type type, Func`3 typeMessageFactory, Func`2 exceptionFactory)
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration
(Type contextType, String configurationTypeName,
Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The type 'MSiH.EyePaid.CigaretteWebApp.DataAccess.CigaretteContext' does not inherit
from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations
configuration types must extend from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
更新
我正在参考一个关于如何在多个上下文中使用EF Migration的示例。
Enable-Migrations -ContextTypeName Foo.CigaretteContext
这个命令出现了错误:
Add-Migration -configuration Foo.CigaretteContext Initial
这个命令是有效的:
Add-Migration Initial