DropCreateDatabaseIfModelChanges EF6 results in System.InvalidOperationException: The model backing the context has changed

前端 未结 5 1188
后悔当初
后悔当初 2021-02-02 15:43

After migrating to Entity Framework 6 I get an error when executing unit tests on the build server.

I\'m using the DropCreateDatabaseIfModelChanges initiali

5条回答
  •  既然无缘
    2021-02-02 15:52

    What works fine for me is excluding the migrations using define. Here is how:

    • Create a new configuration called Test that defines TEST
    • In your tests, throw an error when TEST is not defined.
    • Exclude your migrations when TEST is defined:
    #if !TEST
    internal sealed class Configuration : DbMigrationsConfiguration
    {
        //...
    }
    #endif
    

    You might need to exclude all of your migrations, which isn't totally satisfying either (but I haven't tried it because I don't have any migrations yet).

提交回复
热议问题