The model backing the context has changed since the database was created.

Just found out the answer and thought of updating here. Just need to do the following.

public class AddressBook: DbContext
{
   protected override void OnModelCreating(ModelBuilder modelBuilder)
   {
    modelBuilder.IncludeMetadataInDatabase = false;
   }
}

以下内容引用自:http://www.cnblogs.com/libingql/p/3351275.html

Entity Framework数据库初始化方式

Entity Framework通过Database.SetInitializer来指定需要的数据库初始化方式,Database.SetInitializer可指定的数据库共有3种:

  1>. CreateDatabaseIfNotExists

  CreateDatabaseIfNotExists是Database.SetInitializer指定数据库的默认方式,用于当数据库不存在时,自动创建数据库。由于该方式是默认方式,所以可以不需要任何代码进行指定,当然也可以使用代码来明确的指定。

Database.SetInitializer(new CreateDatabaseIfNotExists<PortalContext>());

  2>. DropCreateDatabaseWhenModelChanges

  DropCreateDatabaseWhenModelChanges用于当数据模型发生改变时,先删除原数据库,后创建新的数据库。

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<PortalContext>());

  3>. DropCreateDatabaseAlways

  DropCreateDatabaseAlways用于每次均先删除原数据库再创建新的数据库,不管数据模型是否发生改变。

Database.SetInitializer(new DropCreateDatabaseAlways<PortalContext>());

  但是,在很多时候,我们希望即使在Entity Framework Code First与数据库不匹配时,宁可Entity Framework Code First报出数据库连接错误,而不希望对数据库进行任何的删除创建操作。Entity Framework Code First提供关闭数据库初始化操作:

Database.SetInitializer<PortalContext>(null);

你可能感兴趣的:(The model backing the context has changed since the database was created.)