1、打开程序包管理器控制台 PM> enable-migrations –EnableAutomaticMigration:$true
2、项目工程文件中会生成Migrations文件夹
3、找到数据库上下文中的构造函数中,如
public StudentDB() : base("name=StudentDB") { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentDB, DataMigrationDemo.Migrations.Configuration>("StudentDB")); }
4、找到Migrations文件夹下的Configuration.cs,在构造函数中输入 AutomaticMigrationDataLossAllowed = true 如
public Configuration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; ContextKey = "DataMigrationDemo.StudentDB"; }
2在