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 'ProductModel' context has changed since the database was create
解决方法:
1.打开当前项目中的:程序包管理器控制台

2.输入:enable-migrations -ProjectName 'ProductModel' -Force
解释:’ProductModel‘,ef框架model层所在程序集名称,不清楚请看下面操作时图片
看到执行结果:
Checking if the context targets an existing database...
Code First Migrations enabled for project ProductModel.
2.打开 ’ProductModel‘,找到Migrations-Configuration
public Configuration()
{
AutomaticMigrationsEnabled = true; (原来为false,改为true)
AutomaticMigrationDataLossAllowed = false; (是否丢数据)
}
3.输入:update-DataBase -ProjectName 'ProductModel' -Force
看到执行结果:
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
You can use the Add-Migration command to write the pending model changes to a code-based migration.
4.如果发现有问题,重新生成解决方案
下面时操作时的照片:


EF框架CodeFirst the model backing the 'PModelEntities' context has changed since the database was created. Consider using Code First Migrations to update the database的更多相关文章
- 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 ...
- Model backing a DB Context has changed; Consider Code First Migrations
Model增加一个字段,数据库对应的也手动添加了字段但是运行时报错 The model backing the 'TopLogDbContext' context has changed since ...
- .Net EntityFramwork6.0 EF框架开发入门
一.环境 开发环境:Sqlserver2008 R2.Visual Studio2012 二.准备工作 1.新建MVC空项目 2.通过NuGet获取 EntityFramework 包 操作截图 ...
- The model backing has changed
其他信息: The model backing the 'WebTopFormContext' context has changed since the database was created. ...
- EF框架step by step(2)—Model-First
这一篇主要说一下EF框架中,Model First做法,仍然采用上一篇的案例.但增加评论功能.首先打开Blog.edmx文件,在空白处右键,添加新实体Comment,如下图示: 点击确定,关闭窗口. ...
- C# CodeFirst(EF框架)代码优先创建数据库
namespace WebEF.Model{ public class ModelContext:DbContext //继承DBcontext 来自EF框架 { public ModelContex ...
- EF框架step by step(3)—Code-First
CodeFirst是EF框架的第三种方式,也是最为复杂一种方式,本文将以EF4.1版本为基础,简要讲解一下用法,同时,也介绍DbContext的用法. 本文采用的示例仍然是前两篇采用的博客用户的示例. ...
- EF框架搭建小总结--CodeFirst模型优先
前言:之前在下总结编写了一篇 EF框架搭建小总结--ModelFirst模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...
- EF框架搭建小总结--CodeFirst代码优先
前言:之前在下总结编写了一篇 EF框架搭建小总结--ModelFirst模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...
随机推荐
- AngularJS源码解析1:angular自启动过程
angularJS加载进来后,会有一个立即执行函数调用,在源代码的最下面是angular初始化的地方.代码展示: bindJQuery(); publishExternalAPI(angular); ...
- 快速搭建微信小程序开发环境
1.工具软件: 注:本文介绍的工具软件已分享到百度云盘,直接下载并按照本文介绍安装即可. 开发工具 v0.7 百度云链接: https://pan.baidu.com/s/1jIQ7i8A密码: aq ...
- C++多线程编程二
1. 死锁与解锁: #include <iostream> #include <thread> #include <mutex> using namespace s ...
- Bootstrap Table使用方法详解
http://www.jb51.net/article/89573.htm bootstrap-table使用总结 bootstrap-table是在bootstrap-table的基础上写出来的,专 ...
- 阿里云服务器之hexo环境搭建
上一步主要主要讲解云服务器购买和连接云服务器,以及文件的操作.本文主要讲解利用hexo搭建自己的静态博客,在服务器中建立自己的hexo博客环境,最后达到可以远程访问,以及远程git推送到github. ...
- Java NIO学习与记录(三): Scatter&Gather介绍及使用
Scatter&Gather介绍及使用 上一篇知道了Buffer的工作机制,以及FileChannel的简单用法,这一篇介绍下 Scatter&Gather 1.Scatter(分散 ...
- Windows网络服务渗透攻击分类
网络服务渗透攻击分为三类 一.针对于windows系统自带的网络服务的渗透攻击 1.针对于NetBIOS的攻击 NetBIOS以运行在TCP/IP系统中的NBT协议来实现,具体包括在UDP的137端口 ...
- c# 命名空间别名
如果命名空间比较长的话,并且在程序中经常使用,就可以用using来设置命名空间的别名 ,C#引入了别名机制 缩短程序员开发时间如: using NSSerialize = System.Compo ...
- e的理解
1. e是一个重要的常数,但是我一直不知道,它的真正含义是什么. 它不像π.大家都知道,π代表了圆的周长与直径之比3.14159,可是如果我问你,e代表了什么.你能回答吗? 维基百科说: " ...
- Mac 10.12搭建OpenVPN服务器以及客户端的使用
说明:我未实践,大概就是这几个步骤,建议服务器在Linux下搭建效果会更好. 1.用brew下载openvpn brew install openvpn 2.命令行输入 openvpn --versi ...