Thursday, January 19, 2012


Changing the Model in a Code-First MVC Project


  • Created a MVC 3 project
  • Used Code-First to create the db
  • Modified the model (added a column)
  • When I tried to go to the view that referenced the model I got the following error:

{"The model backing the 'TaskDBContext' 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."}


  • I added the following to the Global.asax.cs file (TaskDBContext is what I setup in the model for my Task object):



References

http://weblogs.asp.net/scottgu/archive/2010/08/03/using-ef-code-first-with-an-existing-database.aspx

No comments:

Post a Comment