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的更多相关文章

  1. 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 ...

  2. Model backing a DB Context has changed; Consider Code First Migrations

    Model增加一个字段,数据库对应的也手动添加了字段但是运行时报错 The model backing the 'TopLogDbContext' context has changed since ...

  3. .Net EntityFramwork6.0 EF框架开发入门

    一.环境 开发环境:Sqlserver2008 R2.Visual Studio2012   二.准备工作 1.新建MVC空项目 2.通过NuGet获取 EntityFramework 包  操作截图 ...

  4. The model backing has changed

    其他信息: The model backing the 'WebTopFormContext' context has changed since the database was created. ...

  5. EF框架step by step(2)—Model-First

    这一篇主要说一下EF框架中,Model First做法,仍然采用上一篇的案例.但增加评论功能.首先打开Blog.edmx文件,在空白处右键,添加新实体Comment,如下图示: 点击确定,关闭窗口. ...

  6. C# CodeFirst(EF框架)代码优先创建数据库

    namespace WebEF.Model{ public class ModelContext:DbContext //继承DBcontext 来自EF框架 { public ModelContex ...

  7. EF框架step by step(3)—Code-First

    CodeFirst是EF框架的第三种方式,也是最为复杂一种方式,本文将以EF4.1版本为基础,简要讲解一下用法,同时,也介绍DbContext的用法. 本文采用的示例仍然是前两篇采用的博客用户的示例. ...

  8. EF框架搭建小总结--CodeFirst模型优先

    前言:之前在下总结编写了一篇 EF框架搭建小总结--ModelFirst模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...

  9. EF框架搭建小总结--CodeFirst代码优先

    前言:之前在下总结编写了一篇 EF框架搭建小总结--ModelFirst模型优先 博文,看到一段时间内该博文的访问量蹭.蹭蹭.蹭蹭蹭...往上涨(实际也不是很多,嘿嘿),但是还是按捺不住内心的喜悦(蛮 ...

随机推荐

  1. html基础整理(02浮动 问题)

    margin的塌陷现象及解决方案    如果一个大盒子中包含一个小盒子,给小盒子设置margin-top,大盒子会一起向下平移 - 解决方案: 1. 给大盒子加一个边框(border) 2. 给大盒子 ...

  2. kali系统越来越大解决

    Kali Linux系统提供的apt-get方式,可以很好的安装软件,对系统进行更新.但是每次执行都会下载大量的软件包.这些软件包被安装后,并不会被自动删掉,会持续占用磁盘空间.解决这个问题有两个办法 ...

  3. Python之scrapy框架之post传输数据错误:TypeError: to_bytes must receive a unicode, str or bytes object, got int

    错误名:TypeError: to_bytes must receive a unicode, str or bytes object, got int 错误翻译:类型错误:to_bytes必须接收u ...

  4. TortoiseGit-2.0.0.0-64bit问题

    使用TortoiseGit拉取一个项目时,提示: disconnected no supported authentication methods available(server sent: pub ...

  5. Maven 问题笔记汇总

    Web项目通过Maven部署到Tomcat的错误. Maven环境下面多项目之间的引用 Maven 远程仓库下载慢的的解决方案 Intellij IDEA 像eclipse那样给maven添加依赖 I ...

  6. [转] flume使用(六):后台启动及日志查看

    [From] https://blog.csdn.net/maoyuanming0806/article/details/80807087 处理的问题flume 普通方式启动会有自己自动停掉的问题,这 ...

  7. Django 登陆注册实现

    路由层 from django.conf.urls import url from django.contrib import admin from app01 import views urlpat ...

  8. webstorm缩进配置

    https://blog.csdn.net/m0_37604745/article/details/80076770 设置代码缩进1. 依次打开files —- settings —- Editor ...

  9. div实现高度自适应的textarea

    textarea使我们常常使用的一种表单形式,多用于大段文字的输入,大多数情况下,textarea都是可以满足需求的,但是当我们希望这个输入框高度自适应的时候,textarea就很难做到了. ok,主 ...

  10. IDE神器intellij idea的基本使用 (转载)

    一.关于新建工程,导入工程,配置jdk,tomcat这里不做过多的讲述,必定网络上关于此类配置一堆一堆的. 二.编码快捷键(比较常用的快捷键)该套快捷键选择的是:Mac OS X 10.5+ 1. a ...