Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"


It is used to dynamically change the database schema and Table Schema in code first approach ,By default entity framework has no migration support under code first technique for security concern .

If we want to apply migration under project then first open package manager console and type


It will create migrations folder under project open configuration.cs and write following code

internal sealed class Configuration : DbMigrationsConfiguration<MvcApplication3.Models.StudentDB>
        public Configuration()
            AutomaticMigrationsEnabled = true;

        protected override void Seed(MvcApplication3.Models.StudentDB context)
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );

now open dbcontext file  and write following code under constructor

public class StudentDB:DbContext
        public StudentDB()
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentDB,MvcApplication3.Migrations.Configuration>());
        public DbSet<Student> Students { get; set; }
        public DbSet<Employee> Employeies { get; set; }

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post