我使用.NET MVC和Entity Framework开发了一个项目。它工作正常。我已经格式化了笔记本电脑,重新安装了Visual Studio,我正在尝试启用迁移和更新数据库。我收到以下错误
PM> update-database -ConfigurationType MessageBoard.Data.MessageBoardContext
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
The type 'MessageBoard.Data.MessageBoardContext' does not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
我检查了以下内容,看起来不错。我不确定为什么会出现上述错误。
安装了实体框架,它可用于解决方案/ 项目
Web.config文件中提供了正确的连接字符串
我可以在更新时启用迁移并获取错误 数据库
我可以成功启用代码迁移并为另一个解决方案更新数据库,但无法启用之前工作正常的解决方案。项目发布没有变更。
我已经探索过现有的链接,并尝试过这些选项。我找不到解决方案
如果我使用-verbose标志运行它并且详细信息在下面给出
,则错误消息是相同的PM> update-database -verbose -ConfigurationType MessageBoard.Data.MessageBoardContext
Using StartUp project 'MessageBoard'.
Using NuGet project 'MessageBoard'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Data.Entity.Migrations.Infrastructure.MigrationsException: The type 'MessageBoard.Data.MessageBoardContext' 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.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.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.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The type 'MessageBoard.Data.MessageBoardContext' does not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
答案 0 :(得分:0)
您使用错误的参数指向上下文。 -ConfigurationType需要迁移配置,而不是上下文。
在运行update-database
https://coding.abel.nu/2012/03/ef-migrations-command-reference/