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 ...
随机推荐
- 第一个Struts1步骤
一.前端 :登陆页面 index.jsp <%@ page language="java" import="java.util.*" pageEncodi ...
- [Leetcode][JAVA] Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- Python time datetime常用时间处理方法
常用时间转换及处理函数: import datetime # 获取当前时间 d1 = datetime.datetime.now() print d1 # 当前时间加上半小时 d2 = d1 + da ...
- php 获取中文字符拼音首字母
//php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...
- 在console中输出图片
console.log("%c\n ","font-size:81px;background:url('http://www.baidu.com/img/bdlogo.g ...
- 自制一个能显示helloworld的最简单OS
<自己动手写操作系统> org 07c00h mov ax,cs mov ds,ax mov es,ax call DispStr jmp $ DispStr: mov ax,BootMe ...
- Atitit..文件上传组件选型and最佳实践总结(2)----断点续传
Atitit..文件上传组件选型and最佳实践总结(2)----断点续传 1. 断点续传的原理 1 2. 如何判断一个插件/控件是否支持断点续传?? 1 3. 常用的组件选型结果::马 1 4. 自定 ...
- atitit.404错误的排查流程总结
atitit.404错误的排查流程总结 #----------jsp head errorPage="" del zeu ok le. #------resin 服务器配置问题 ...
- paip.spring3 mvc servlet的配置以及使用最佳实践
paip.spring3 mvc servlet的配置以及使用最佳实践 1. Web.xml 1 2. springMVC.xml 2 1. mvcAction .mvcAction 2 2. Res ...
- paip.调试js 查看元素事件以及事件断点
paip.调试js 查看元素事件以及事件断点 ff 26 +firebug 查看不出来.. 360 ,虽然也是chrome 基础,但是开发工具烂阿,也是显示不出来.. 作者Attilax 艾龙, ...