首页 > 解决方案 > handle Entity Framework migration when live and development Database is same

问题描述

I am using entity framework 6 with code first approach. I use the same database for live & development purpose, when I make change in model or add new fields in the model, then add-migration and run update-database, migration add and update successfully locally and when run application from visual studio its works fine. But on the other hand my already published same application crashes, when I open the live URL, I see this error

enter image description here

one solution is to re-publish the application to live but I want a different best solution.

I want to know the best practice of working with entity framework , I can add or modify model using EF while live application working fine as it was working before model modification. I am using SQL Server as Database.

标签: c#asp.net-mvcentity-framework-6entity-framework-migrations

解决方案


我将相同的数据库用于实时和开发目的,

这太糟糕了,甚至都不好笑。这意味着你永远不能做出重大改变。这也意味着开发过程中的任何代码错误都可能破坏生产数据。这就像说“我有健康问题。我在吞毒,为什么不好”不好。

标准做法(甚至不是最好的,它是标准的)是为每个环境拥有单独的数据库副本。许多团队甚至为所有或特定开发人员制作数据库副本——即使数据库有几十 TB 大。

但是用于开发和生产的一个数据库副本永远不会起作用,而且它显然会破坏生产数据库。开始使用副本。


推荐阅读