The model backing the 'ApplicationDbContext' context has changed since the database was created

前端 未结 21 1357
情话喂你
情话喂你 2020-12-02 07:24

First of all, I have not seen this error anywhere else and I guess it\'s not a replicate so please read the whole situation first.

Everything was working just fine

相关标签:
21条回答
  • 2020-12-02 07:25

    It was such a strange error,, It wasn't my error at the end, it was Microsoft's,, I installed the Entity framework the " pre-release" version and it was responsible for this error,, when i upgraded to the stable release it disapperared,, thank you everyone believe me when i asked this question i searched like for a week or so for its solution so i am pretty sure that this problem isn't anywhere else : the version of entity framework.dll that caused the problem was 6.0.2 if it helps.

    0 讨论(0)
  • 2020-12-02 07:26

    Just Delete the migration History in _MigrationHistory in your DataBase. It worked for me

    0 讨论(0)
  • 2020-12-02 07:31

    This post fixed my issue. It's all about adding the following line in Application_Start() in Global.asax :

    Database.SetInitializer<Models.YourDbContext>(null);

    However it cause database recreation for every edit in your model and you may loose your data.

    0 讨论(0)
  • 2020-12-02 07:31

    Everybody getting a headache from this error: Make absolutely sure all your projetcs have a reference to the same Entity Framework assembly.

    Short story long:

    My model and my application were in different assemblies. These assemblies were referencing a different version of Entity framework. I guess that the two versions generated a different id for the same modell. So when my application ran the id of the model didn't match the one of the latest migration in __MigrationHistory. After updating all references to the latest EF release the error never showed up again.

    0 讨论(0)
  • 2020-12-02 07:34

    I was having same problem as a7madx7, but with stable release of EF (v6.1.1), and found resolution posted in:

    http://cybarlab.com/context-has-changed-since-the-database-was-created

    with variation in: http://patrickdesjardins.com/blog/the-model-backing-the-context-has-changed-since-the-database-was-created-ef4-3

    2nd link includes specific mention for VB..... "you can simply add all the databasecontext that are having this problem on your app_start method in the global.asax file like this":

    Database.SetInitializer(Of DatabaseContext)(Nothing)
    

    NB: i had to replace "DatabaseContext" with the name of my class implementing DbContext

    Update: Also, when using codefirst approach to connect to existing tables, check database to see if EF has created a table "_migrationhistory" to store mappings. I re-named this table then was able to remove SetInitializer from global.asax.

    0 讨论(0)
  • 2020-12-02 07:34

    remove all tables identity

    Delete _MigrationHistory
    Delete AspNetRoles
    Delete AspNetUserClaims
    Delete AspNetUserLogins
    Delete AspNetRoles
    Delete AspNetUser
    
    0 讨论(0)
提交回复
热议问题