The model backing the <Database> context has changed since the database was created.
Just found out the answer and thought of updating here. Just need to do the following.
public class AddressBook: DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.IncludeMetadataInDatabase = false;
}
}
以下内容引用自:http://www.cnblogs.com/libingql/p/3351275.html
Entity Framework数据库初始化方式
Entity Framework通过Database.SetInitializer来指定需要的数据库初始化方式,Database.SetInitializer可指定的数据库共有3种:
1>. CreateDatabaseIfNotExists
CreateDatabaseIfNotExists是Database.SetInitializer指定数据库的默认方式,用于当数据库不存在时,自动创建数据库。由于该方式是默认方式,所以可以不需要任何代码进行指定,当然也可以使用代码来明确的指定。
Database.SetInitializer(new CreateDatabaseIfNotExists<PortalContext>());
2>. DropCreateDatabaseWhenModelChanges
DropCreateDatabaseWhenModelChanges用于当数据模型发生改变时,先删除原数据库,后创建新的数据库。
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PortalContext>());
3>. DropCreateDatabaseAlways
DropCreateDatabaseAlways用于每次均先删除原数据库再创建新的数据库,不管数据模型是否发生改变。
Database.SetInitializer(new DropCreateDatabaseAlways<PortalContext>());
但是,在很多时候,我们希望即使在Entity Framework Code First与数据库不匹配时,宁可Entity Framework Code First报出数据库连接错误,而不希望对数据库进行任何的删除创建操作。Entity Framework Code First提供关闭数据库初始化操作:
Database.SetInitializer<PortalContext>(null);
The model backing the <Database> context has changed since the database was created.的更多相关文章
- EF框架CodeFirst the model backing the 'PModelEntities' context has changed since the database was created. Consider using Code First Migrations to update the database
1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the 'Produc ...
- Model backing a DB Context has changed; Consider Code First Migrations
Model增加一个字段,数据库对应的也手动添加了字段但是运行时报错 The model backing the 'TopLogDbContext' context has changed since ...
- The model backing the 'XXX' context has changed 错误
https://blog.csdn.net/hit_why/article/details/72778785 https://blog.csdn.net/hit_why/article/details ...
- Entity Framework : The model backing the '' context has changed since the database was created
1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the '' cont ...
- The model backing has changed
其他信息: The model backing the 'WebTopFormContext' context has changed since the database was created. ...
- The entity type XXX is not part of the model for the current context.
今天遇到了一个奇葩问题,虽然解决了,但还是一脸懵,先附赠一下别人的解决方案:https://www.cnblogs.com/zwjaaron/archive/2012/06/08/2541430.ht ...
- Sql server在使用sp_executesql @sql执行文本sql时,报错: Could not find database ID 16, name '16'. The database may be offline. Wait a few minutes and try again.
最近在公司项目中使用exec sp_executesql @sql执行一段文本sql的时候老是报错: Could not find database ID 16, name '16'. The dat ...
- The backup set holds a backup of a database other than the existing ‘dbName’ database
[Solved] System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than t ...
- The entity type <type> is not part of the model for the current context
这是在网站里遇到的一个错误,自动生成的不能手动添加, reference: http://stackoverflow.com/questions/19695545/the-entity-type-xx ...
随机推荐
- sql关键字的解释执行顺序
sql关键字的解释执行顺序 分类: 笔试面试总结2013-03-17 14:49 1622人阅读 评论(1) 收藏 举报 SQL关键字顺序 表里面的字段名什么符号都不加,值的话一律加上单引号 有一 ...
- 《Diagnostic use of facial image analysis software in endocrine and genetic disorders: review, current results and future perspectives》学习笔记
<使用面部图像分析软件诊断内分泌和遗传疾病:回顾,当前研究结果以及未来展望> Abstract 库欣综合征(CS)和肢端肥大症普遍是在发病后几年才能被诊断出的内分泌疾病.现在需要新的诊断方 ...
- java中Class.getResource用法
用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大常最经常用的,就是用JAVA的File类,如要取得c:/test.txt文件,就会这样用File file ...
- [MSSQL2012]LEAD函数
LEAD函数简单点说,就是把下一行的某列数据提取到当前行来显示,看示例更能解释清楚,先看测试用脚本 DECLARE @TestData TABLE( ID INT IDENTITY(1,1), ...
- SQL Server使用文件组备份降低备份文件占用的存储空间
对于DBA来说,备份和刷新简历是最重要的两项工作,如果发生故障后,发现备份也不可用,那么刷新简历的重要性就显现出来,哇咔咔!当然备份是DBA最重要的事情(没有之一),在有条件的情况下,我们应该在多个服 ...
- [BTS] The value "" for the property InboundId is invalid
Microsoft.ServiceModel.Channels.Common.MetadataException: Retrieval of Operation Metadata has failed ...
- duilib进阶教程 -- 响应windows原生消息和自定义消息(13)
一.windows原生消息 同样,入门教程只是给出了响应windows原生消息的方法,并没给出例子,这里以自适应屏幕分辨率为例.迅雷播放器虽然可以在启动的时候自动调整窗口大小,但是当屏幕分辨率实时改变 ...
- atitit.编程语言 程序语言 的 工具性 和 材料性 双重性 and 语言无关性 本质
atitit.编程语言 程序语言 的 工具性 和 材料性 双重性 and 语言无关性 本质 #---语言的 工具和材料双重性 有的人说语言是个工具,有的人说语言是个材料..实际上语言同时属于两个属性. ...
- 菜鸟学习WCF笔记-概念
背景 WCF这个词语一直不陌生,以前也使用过多次在实际的项目中,但是一直没有时间来做个系统的学习,最近抽点时间,看看 蒋金楠的<WCF全面解析>学习下,顺带做些笔记,如有错误,欢迎各路大神 ...
- Spark Scala 读取GBK文件的方法
1. 在生产环境下,很多文件是GBK编码格式的,而SPARK 常用的textFile方法默认是写死了读UTF-8格式的文件,其他格式文件会显示乱码 用如下代码实现读取GBK文件的方法 import o ...