![](/img/trans.png)
[英]Entity Framework Core Code First Update-Database does nothing
[英]Not able to update-database with Code First Entity Framework 6.1
在我的项目中,我首先使用代码,并且能够通过nuget软件包管理器控制台创建数据库并对其进行迁移。
现在,我在应用程序中添加了第二个数据库上下文,并且该上下文不是第一个代码。 此上下文建立在现有数据库上。
添加第二个上下文后...如果尝试执行更新数据库,则会收到错误消息
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.NotSupportedException: Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml)
at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
但是,我只希望将迁移应用于我的第一个上下文,并且希望不考虑第二个上下文。
通过直接指定要更新的配置类型解决了该问题
更新数据库-ConfigurationTypeName Company.Project.Migrations.MySpecificConfiguration
这篇文章很有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.