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模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...
随机推荐
- robot framework-接口测试实例一
需求:api/car/detail/recommendcar.json 接口返回的车辆数量少于等于20且车辆不能重复 分析:统计接口中返回的列表的长度,再把carid拿出来组成一个新的列表,判断这 ...
- 工作中遇到的两个问题-正则以及console
一.今天做点击按钮验证邮箱时,遇到以下几个问题: (1)点击按钮后,执行if(regExp.test(str)),出现一种奇怪的现象:第一次输入正确邮箱验证通过,第二次输入正确邮箱就返回false,第 ...
- php prepare
详见 https://stackoverflow.com/questions/134099/are-pdo-prepared-statements-sufficient-to-prevent-sql- ...
- hive连接mysql遇到的问题
启动hive之前应该先启动metastore,也是在bin目录下:./hive --service metastore &然后再启动hive: ./hive 今天连接hive时总是报错:Una ...
- ThreadLocal系列(一)-ThreadLocal的使用及原理解析
ThreadLocal系列之ThreadLocal(源码基于java8) 项目中我们如果想要某个对象在程序运行中的任意位置获取到,就需要借助ThreadLocal来实现,这个对象称作线程的本地变量,下 ...
- Mac下使Iterm2开机启动不显示界面
一.在登录项上添加Iterm2的启动项 二.打开Iterm2 1.启动后会显示Iterm2,此时点击关闭按钮,保证桌面上没有任何的控制台窗口. 2.按[Command]+[Shift]+[S],保存名 ...
- Mac下安装tomcat8(Mac 10.12)
1.到官网下载tomcat8 http://tomcat.apache.org/download-80.cgi 说明:tomcat最好不要下载最新的,选择一个适中的最好. 2.安装 ▲解压并重命名文件 ...
- Python3 print()函数sep,end,file参数用法练习
来自builtins.py:def print(self, *args, sep=' ', end='\n', file=None): # known special case of print &q ...
- (转)Centos7上部署openstack ocata配置详解
原文:http://www.cnblogs.com/yaohong/p/7601470.html 随笔-124 文章-2 评论-82 Centos7上部署openstack ocata配置详解 ...
- 下载windows版本apache网页服务器
1.进入apache服务器官网http://httpd.apache.org/,这里我们以下载稳定版的httpd 2.4.25为例,点击download. 2.点击链接Files for Micros ...