Skip to content

Instantly share code, notes, and snippets.

@rafaelune
Last active December 10, 2019 19:01
Show Gist options
  • Save rafaelune/f6a80942d47590954f8b to your computer and use it in GitHub Desktop.
Save rafaelune/f6a80942d47590954f8b to your computer and use it in GitHub Desktop.

Code First Migrations - Entity Framework

Package Manager Console

Enable migrations for your context.

  PM> Enable-Migrations

Creates scaffold for the next migration based on changes you have made to your model since the last migration was created.

  PM> Add-Migration MigrationName

Applies all pending migrations to the database.

  PM> Update-Database

Applies all pending migration to the database and logs executed sql scripts to console.

  PM> Update-Database –Verbose

Applies the specific migration to the database. This can also be used to downgrade to the specific migration.

  PM> Update-Database –TargetMigration: MigrationName

Rollback all migrations

  PM> Update-Database –TargetMigration:0

Generates a sql script file of all migrations.

  PM> Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: LastMigrationName

If you don’t specify a target migration, Migrations will use the latest migration as the target. If you don't specify a source migrations, Migrations will use the current state of the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment