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模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...
随机推荐
- GraphQL 如何取代 Redux
简评:使用 GraphQL 可以大大简化客户端状态管理部分的代码. ⚛️切换到React 故事背景:在 2016 年,Pathwright 的前端团队就开始将客户端的代码从 Backbone & ...
- python-----读写操作
1. 文件的读取 注意:在windows中文件的路径是这样:C:\Users\name\mystuff .由于\u在python中表示转义如果使用此文件路径就会报错.解决方法: a.把斜杠\改为反斜杠 ...
- Sci-Hub
提到Sci-Hub这个文献下载利器,大家肯定都不陌生.你在各大SCI杂志上看到的英文文献,90%以上都能免费下载.因为它严重侵犯了爱思唯尔.施普林格.Wiley等各大出版商的利益,遭到起诉与封杀. 不 ...
- LOJ2476. 「2018 集训队互测 Day 3」蒜头的奖杯 & LOJ2565. 「SDOI2018」旧试题(莫比乌斯反演)
题目链接 LOJ2476:https://loj.ac/problem/2476 LOJ2565:https://loj.ac/problem/2565 题解 参考照搬了 wxh 的博客. 为了方便, ...
- BZOJ3168. [HEOI2013]钙铁锌硒维生素(线性代数+二分图匹配)
题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=3168 题解 首先,我们需要求出对于任意的 \(i, j(1 \leq i, j \leq ...
- webpack打包报错Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead
npm install –save-dev extract-text-webpack-plugin@next 会下载到+ extract-text-webpack-plugin@4.0.0-beta. ...
- 2018沈阳网络赛 - Ka Chang KD树暴力
题意:给你一棵树,n个点q次操作,操作1查询x子树深度为d的节点权值和,操作2查询子树x权值和 把每个点按(dfn,depth)的二维关系构造kd树,剩下的只需维护lazy标记即可 #include& ...
- CentOS下搭建DHCP服务
DHCP的原理这里就不多说了,这里直接贴配置加解说 1.安装dhcp yum -y install dhcp-4.1.1-63.P1.el6.centos.x86_64 2.编辑/etc/dhcp/d ...
- Access network
1 State transfering A•Mobility:开机-搜寻PLMN/CELL来发现自己在网络中的位置•Attach request•Auth request•Auth res ...
- 微信小程序授权流程(图)
看图: 1. 前端H5调用JSSKD的方法 wx.login(), 2. 微信返回 临时登录凭证code 给前端H5 3. 将此Code给到开发者服务器 4. 服务器混同小程序的AppId 和 Ap ...