Last post Nov 08, 2012 09:05 PM by vectorman
May 14, 2011 06:00 PM|cummer_mcneal|LINK
I have a database that has already been there. When I run my application, I get the error:
The model backing the 'ZZZDB' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy
will automatically delete and recreate the database, and optionally seed it with new data.
Would someone be able to explain what needs to be done as I do not have the prerogative to delete the database and recreate it. I don't think it is right for my application to use DbDatabase.SetInitializer to auto-delete and recreate the database.
Is there another way to correct the problem (e.g. allow MVC to auto calculate the HASH value or something)?
May 15, 2011 07:58 AM|chohmann|LINK
Delete the EdmMetadata table in your database and update your entity framework model to reflect any changes you made.
May 16, 2011 06:02 PM|cummer_mcneal|LINK
Perhaps, I failed to mention that the development team used the Database First approach using SQL Server Management Tool. MVC was not used on it yet; therefore, there is no EdmMetadata table existing on the database yet. Would you mind expounding on how
to create the EdmMetadata table and how to update the entity framework model?
Your help is much appreciated.
May 16, 2011 06:46 PM|chohmann|LINK
If this is a database-first scenario then there's no need to delete the EdmMetadata table since it does not exist. Simply update your entity model to reflect the changes in the underlying database. Here's a video on the database-first approach:
How did you create your model? Did you use the Entity Data Model designer with the DbContext Generator or did you manually create POCO classes and a DbContext class? If you used the designer, then you can simply right click on the design surface and select
"Update Model from Database". If you manually created POCO classes and a DbContext class, you will need to update those classes manually to reflect the changes in the database.
May 17, 2011 07:43 PM|cummer_mcneal|LINK
Thank you very much for the tutorial. It was simple and suited very much the environment I have. To answer your question, I used SQL Server Management Studio to build the database. I simply followed the tutorial and it worked perfectly. The only thing
I would emphasize is the instantiation within the controller. It should be the DbContext instantiation rather than the table itself.
Now, my first application worked.
Nov 08, 2012 09:05 PM|vectorman|LINK
I have the same problem. I dont have any edmx file. im beginner on MVC4 , razor i have model class. I changed my model model class. (added one filed) how i can update my schema from model automaticly?