Entity Framework creates empty migration but insists that my model is different

后端 未结 2 893
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 08:56

Today is a sad day. First thing today I saw EF exception saying that \"The model backing the \'DomainContext\' context has changed since the database was created.\"

相关标签:
2条回答
  • 2021-01-12 09:39

    I had the same problem today. I added before the problem appeared a ViewModel, a View and Html.EnableClientValidation()

    There was no Model changes at all! I did a dummy change, like @Guilleon advised, and created a working Migration... but it didn't help.

    Then I restarted the Visual Studio and everything worked again. It must be a glitch

    0 讨论(0)
  • 2021-01-12 09:53

    The cause to my problem was a [AllowHtml] attribute applied to one of the models. The trouble started to happen after I've updated MVC to 5.1.1 and WebApi to 2.1.

    I've removed that attribute from EF-Model and stripped and re-build the database and the problem was gone.

    I've written up a blog post on how to debug this kind of problems: http://tech.trailmax.info/2014/03/inside_of_ef_migrations/

    Also I think this [AllowHtml] attribute is a bug, I'll create a reproducible solution and will submit the bug report to EF-people.

    Update: I actually could never reproduce the error. [AllowHtml] attribute on class properties had nothing to do with it. A magical glitch that was.

    0 讨论(0)
提交回复
热议问题