Entity Framwork (EF) Code First Migration – Cheat Sheet

Entity Framework (EF) Code First Migrations are powerful commands to quickly update your data model based on your code changes.  Enjoy the list of commands as a simple cheat sheet.

Enable Migrations

Enable-Migrations

Add Migration

Create New Migration

Add-Migration <migration_name>

Overwrite Migration

Add-Migration <migration_name> -Force

Update Database

Latest Migration

Update-Database

Specific Migration

Update-Database -TargetMigration:”MigrationName”

Rollback Database

All Migrations

Update-Database -TargetMigration:0

Specific Migration

Update-Database -TargetMigration:”MigrationName”

SQL Scripts

All Migrations

Update-Database -Script -SourceMigration: $InitialDatabase

Specific Migration

Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: <migration_name>

Update-Database -Script -SourceMigration: <migration_name> -TargetMigration: <migration_name>

Nate Bunton

Nate Bunton is a Lead Software Engineer at Meta Payment Systems. He has over 10 years developing software and leading teams. He works with the Microsoft technology stack focusing in ASP.NET, MVC, HTML, JavaScript, CSS and Web Security. Nate also focuses on Application Lifecycle Management (ALM) engaging his teams with key stakeholders using a variety of agile principals. At Meta Payment Systems, Nate has been a leader in driving technology in the enterprise from new Web Technology to Service Oriented Architecture using WCF and NServiceBus. Nate’s greatest passion is for User Experience, Web Technology and Engaging Teams. He is driven by his desire for continuous learning & improvement.

Posted in Web Development Tagged with: , ,