1.3.3.Code-first Migrations

  • 1.Enable migration

    • Open tools -> NuGet package Manager ->

    • Type in package manager console:

      enable-migrations

  • 2.Add migration

    • Type in package manager console:

      add-migration 'InitailModel'

    • It will generate migration files to ~/Migrations according to models witch implement IdentityDbContext or add model to IdentityModels.cs

      public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
      {
        public DbSet<Customer> Customers { get; set; }
      }
    • If you want to update migration files, type:

      add-migration InitailModel -Force

  • 3.Update database

    • Type in package manager console:

      update-database

    • Check database and tables from ~/App_Data

  • 4.Check database

    • 1.Open solution explore

    • 2.Show all files

Last updated