1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构。再次运行时出现一下问题:

Entity Framework : The model backing the '' 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.

输入: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.

3.打开 ’ProductModel‘,找到Migrations-Configuration

public Configuration()
{
    AutomaticMigrationsEnabled = true;     (原来为false,改为true)
              AutomaticMigrationDataLossAllowed = false;   (是否丢数据)
}

下面时操作时的照片:

Entity Framework : The model backing the '' context has changed since the database was created的更多相关文章

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

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

  3. [转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)

    本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-a ...

  4. How to: Use the Entity Framework Data Model Located in an External Assembly 如何:使用位于外部程序集中的EF数据模型

    If you have a non-XAF application, and want to develop an XAF application that utilizes the same dat ...

  5. 第三篇:Entity Framework CodeFirst & Model 映射 续篇 EntityFramework Power Tools 工具使用

    上一篇 第二篇:Entity Framework CodeFirst & Model 映射 主要介绍以Fluent API来实作EntityFramework CodeFirst,得到了大家一 ...

  6. 第二篇:Entity Framework CodeFirst & Model 映射

    前一篇 第一篇:Entity Framework 简介 我有讲到,ORM 最关键的 Mapping,也提到了最早实现Mapping的技术,就是 特性 + 反射,那Entity Framework 实现 ...

  7. How to: Supply Initial Data for the Entity Framework Data Model 如何:为EF数据模型提供初始数据

    After you have introduced a data model, you may need to have the application populate the database w ...

  8. 【Entity Framework】Model First Approach

    EF中的model first 所谓mf, 就是使用vs提供的edm designer去设计model,然后将设计好的model使用vs在指定的数据库中生成数据库即可. 当你的项目既没有数据库也没有c ...

  9. Entity Framework之Model First开发方式

    一.Model First开发方式 在项目一开始,就没用数据库时,可以借助EF设计模型,然后根据模型同步完成数据库中表的创建,这就是Model First开发方式.总结一点就是,现有模型再有表. 二. ...

随机推荐

  1. PHP机器学习库php-ml的简单测试和使用

    php-ml是一个使用PHP编写的机器学习库.虽然我们知道,python或者是C++提供了更多机器学习的库,但实际上,他们大多都略显复杂,配置起来让很多新手感到绝望.php-ml这个机器学习库虽然没有 ...

  2. MySQL · 引擎特性 · InnoDB奔溃恢复

    前言 数据库系统与文件系统最大的区别在于数据库能保证操作的原子性,一个操作要么不做要么都做,即使在数据库宕机的情况下,也不会出现操作一半的情况,这个就需要数据库的日志和一套完善的奔溃恢复机制来保证.本 ...

  3. OCP 11G 实验环境安装文档 ( RedHat5.5 + Oracle11g )

    RedHat5.5 linux下Oracle11g软件安装 一.配置虚拟机 为了创建和配置虚拟机,你需要添加硬件设备如磁盘和cpu,在你开始安装之前,创建一个windows目录作为存放虚拟机的目录 目 ...

  4. 常用PHP函数

    md5_file() 生成md5 $zip = new \ZipArchive(); if($zip->open($savepath.$key) === TRUE){ $zip ->ext ...

  5. sed的粉丝

    UNIX/LINUX下有个工具叫sed,起源于ed命令,但没有人机交互,完全是脚本语言.sed虽然是结构化的程序,但其虚拟出来的机器与我们实际机器相差甚远,依靠模式空间和保留空间的交替使用.正则表达式 ...

  6. 使用Publish Over SSH插件实现远程自动部署

    背景: 现场的部署环境开放外网环境困难,只有一台机器能够开发外网,应对该情况,所有的补丁文件需要直接在master机器上面生成,然后命令移动到其他的服务器上面去. 这里使用到了jenkins的Publ ...

  7. c#中Class和Struct使用与性能的区别

    在Unity中很多已经定义为结构体的数据结构 Vector2, Vector3 和 Vector4 Rect Color和Color32 Bounds Touch   1.Class为引用类型,Str ...

  8. ubuntu下使用 chkconfig 是一种习惯

    ubuntu下使用 chkconfig 是一种习惯 习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单. 如下: 第一步, 安装sysv-rc-conf sudo apt instal ...

  9. IDEA 2017注册码破解方法(转)

    进入ide主页面,help-register-license server,然后输入 http://idea.iteblog.com/key.PHP(注意:php要小写)即可~ 如下图: 点击 Act ...

  10. Java中的24种设计模式与7大原则 (转)

    一.创建型模式 1.抽象工厂模式(Abstract factory pattern): 提供一个接口, 用于创建相关或依赖对象的家族, 而不需要指定具体类.2.生成器模式(Builder patter ...