EF框架CodeFirst the model backing the 'PModelEntities' context has changed since the database was crea...

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

下面时操作时的照片:

 

转载于:https://www.cnblogs.com/haibozhu/p/7426665.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值