locked
EF Update Database Bug? ASP MVC Application RRS feed

  • Question

  • Hi all,

    Getting a frustrating issue at the moment where I am geting the error, "The model backing the 'AscertusWebDbContext' context has changed since the database was created", even though I have just run update-database which appears to have completed successfully.

    So, steps I reverted to:

    1. Delete database from (localdb)\v11.0 instance
    2. Run add-migration blah
    3. Run update-database
    4. Debug the web application
    5. Get the error above

    Now the only thing I can think is that something has changed in the Microsoft underlying 'Organisational' authentication classes because I moved the two tables Tenants and IssuingAuthorityKeys from the default context into the DAL dll that I use which has its own context.

    So I created a new MVC project using the same Organisation Authentication and the new classes created were exactly the same as what I am using both tables just have a sing string Id field in them.

    The last thing I tried was to rollback to a previous target migration, make a change and force a rescaffolding of the last migration I created. The migration history shows the migration applied, the change has been applied to the table but I still get the same error.

    Any help appreciated, where do I start looking for this problem as I'm getting zero feedback from anywhere I can think of.

    Thanks

    Stu

    Friday, April 10, 2015 3:27 PM

Answers

  • Hello Stu,

    It is hard to tell if it is a bug in EF, could you please provided a sample demo code which could reproduce this issue: your entity class code, your detail steps could causes this issue?

    Here is a thread I found which discusses a similar issue:

    The model backing the <Database> context has changed since the database was created.

    It provides a workaround is to place Database.SetInitializer<YourDbContext>(null);  into you Application_Start method. You could have a try.

    >> Now the only thing I can think is that something has changed in the Microsoft underlying…

    You could have a try to validate the generated model to check if they are matched according to this article(as you can see, there is a emdx model file even for code first approach)

    http://www.tecsupra.com/how-to-decode-the-model-column-of-the-migrationhistory-table-in-ef-migrations/

    I notice that you are working with the MVC project, I suggest that you could create a same demo and do the same steps with a Console  application to check if it is caused by the MVC project, if so, I think MVC experts could help you on MVC forum.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Stuart Bailey Thursday, June 16, 2016 7:09 AM
    Monday, April 13, 2015 2:49 AM