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 ... 
随机推荐
- 传递引用类型参数(ref)
			引用类型的变量不直接包含其数据:它包含的是对其数据的引用. 当通过值传递引用类型的参数时,有可能更改引用所指向的数据,如某类成员的值. 但是无法更改引用本身的值:也就是说,不能使用相同的引用为新类分配 ... 
- Virtualbox修改bios信息安装Windows XP OEM
			转载 http://hi.baidu.com/guoyao11/item/631ad6eb4fb3d93887d9de11 具体方法有两个: 1.把下面的代码复制改后缀为BAT文件直接运行即可,以Le ... 
- JS检测浏览器是否支持HTML5视频播放 (标签<video>) ,
			function checkVideo() { if (!!document.createElement('video').canPlayType) { var vidTest = document. ... 
- php笔试题(3)--转载
			1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hello tush ... 
- 改进ConcurrentDictionary并行使用的性能
			上一篇文章“ConcurrentDictionary 对决 Dictionary+Locking”中,我们知道了 .NET 4.0 中提供了线程安全的 ConcurrentDictionary< ... 
- [译]面向初学者的Asp.Net状态管理技术
			介绍 本文主要讲解Asp.Net应用程序中的状态管理技术(Asp.Net中有多种状态管理技术),并批判性地分析所有状态管理技术的优缺点. 背景 HTTP是无状态的协议.客户端发起一个请求,服务器响应完 ... 
- [WinAPI] 串口读写
			#include <stdio.h> #include <stdlib.h> #include <windows.h> HANDLE hComm; OVERLAPP ... 
- 配置SharePoint 2013 Search 拓扑结构
			在单台服务器上安装了 SharePoint Server 2013,并且创建了具有默认搜索拓扑的 Search Service 应用程序.在默认搜索拓扑中,所有搜索组件都位于承载管理中心的服务器上.S ... 
- Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)
			介绍:什么是线程,线程的优点是什么 线程在Unix系统下,通常被称为轻量级的进程,线程虽然不是进程,但却可以看作是Unix进程的表亲,同一进程中的多条线程将共享该进程中的全部系统资源,如虚拟地址空间, ... 
- fgets函数执行完成后,文件指针如何移动?
			用fgets执行之后,读取了文件中的一行,这时文件位置指针是自动指向文件的下一行的开头吗,还是指向当前行的结尾?如果一行的字符串没读取完会怎样? 实例结果: 如果一行的字符串没读取完会,下一次会接着上 ... 
