Code-based Migration in EF code first approch

In Migration we have two type of migration

  1. Automated Migration
  2. Code-based Migration

Below information’s are for Code-based Migration

Enable-Migrations: Enables the migration in your project by creating a Configuration class.
PM> Enable-Migrations

Add-Migration: Creates a new migration class as per specified name with the Up() and Down() methods.
PM> Add-Migration "MigrationName"
The above command will create a “timestamp_MigrationName”.cs file with the Up() and Down() methods

Update-Database: Executes the last migration file created by the Add-Migration command and applies changes to the database schema.
PM> Update-Database

Rollback Migration to previous one
PM> update-database -TargetMigration:"timestamp_MigrationName

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: