码迷,mamicode.com
首页 > 数据库 > 详细

Entity Framework : The model backing the '' context has changed since the database was created

时间:2017-08-25 11:01:45      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:包管理器   explicit   tab   back   can   包管理   项目   blog   upd   

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.如果发现有问题,重新生成解决方案

下面时操作时的照片:

技术分享

技术分享

 

Entity Framework : The model backing the '' context has changed since the database was created

标签:包管理器   explicit   tab   back   can   包管理   项目   blog   upd   

原文地址:http://www.cnblogs.com/haibozhu/p/7426665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!