Entity Framework Migration: Why does it ignore snapshot and take __MigrationHistory into account?

风流意气都作罢 提交于 2020-01-16 07:07:10

问题


I'm using EF 6.0.0 and .Net 4.5.

I face a very confusing problem. Me and one of my colleagues are working on the domain model section of our project on two different clients. The problem is:

1- Me and my colleagues start with the absolutely identical project and we are completely synced with the source control.

2- When I change the model for example add a property then Add-Migration FromA then Update-Database it works great. The generated code file contains just one command that is to add the column.

3- Meanwhile, after the db is updated and just before I check in something to source control, my colleague adds another property and then Add-Migration FromA then Update-Database. And guess what? This generated code file has a command to drop the column I newly added!!!

I added another column using native Sql, and fortunately the column is not going to be deleted.

I deleted the __MigrationHistory table and the remove column didn't get generated.

I turned off initializer Database.SetInitializer<MyContext>(null), no success.

So, my guess is that EF Migrations compares current model with the last one stored in __MigrationHistory table not the last local snapshot stored in .resx file. Am I right? Any way to solve the problem?

来源:https://stackoverflow.com/questions/30822852/entity-framework-migration-why-does-it-ignore-snapshot-and-take-migrationhist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!