EV: Exception when Using EF “Code First” with an Existing Database

Exception when Using EF “Code First” with an Existing Database
 
The error message

"The model backing the 'AddressBook' 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 RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data."

Official Solution
Database.SetInitializer(null);
 
Better Solution
If you find there is a table named like __MigrationHistory under Tables\System Tables in SQL Server Management Studio, just deleted it. Then, the exception will go away.
 

posted on 2013-12-27 09:53  weihongji  阅读(215)  评论(0编辑  收藏  举报

导航