Where is that file on my system?

后端 未结 1 1758
忘掉有多难
忘掉有多难 2021-01-23 21:07

Am trying to learn ASP.NET MVC and search the internet in and out including SO. A lot of questions and answers about |DataDirectory| as where and how.

When debugging the

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-23 21:35

    The answer to your problem lies in reading Scott Guthrie's blog

    For those who are seeing this exception:

    "The model backing the 'Production' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance."

    Here is what is going on and what to do about it:

    When a model is first created, we run a DatabaseInitializer to do things like create the database if it's not there or add seed data. The default DatabaseInitializer tries to compare the database schema needed to use the model with a hash of the schema stored in an EdmMetadata table that is created with a database (when Code First is the one creating the database). Existing databases won’t have the EdmMetadata table and so won’t have the hash…and the implementation today will throw if that table is missing. We'll work on changing this behavior before we ship the fial version since it is the default. Until then, existing databases do not generally need any database initializer so it can be turned off for your context type by calling:

    Database.SetInitializer(null);
    

    Hope this will help you resolve the issue.

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