Entity Framework Code Only error: the model backing the context has changed since the database was created?

I found the answer in the comments on this post on Scott Guthrie's blog.

I found the answer in the comments on this post on Scott Guthrie's blog. weblogs.asp.net/scottgu/archive/2010/08/... 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).

This is a bug in CTP4 for using EF with pre-existing databases. You can fix it by calling: Database. SetInitializer(null); in the Application_Start method of Global.asax.

No but you can change connection string, create database again and use some diff tool to compare databases (for example Visual Studio 2010 Premium or Ultimate, or tools from RedGate).

Hmmm, its rather annoying as I have just done what you have suggested, but generated all the scripts from the databases in question and they match, however the hash that the EdmMetadata holds is different... thanks for the idea though, at least I know that the databases are the same and I am not going around the bend – didiHamman Mar 17 at 16:00 You can turn off this check. – Ladislav Mrnka Mar 17 at 16:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions