Entity Framework Code First migration command, codefirst
I. Enable-Migrations
Note:Enable migration for the project. This command adds the Migrations folder for the project, including two files:
Configuration class: This class allows context-based Configuration migration.
InitialCreate migration: this migration is generated before migration is enabled. If the database is not generated before Migration is enabled, the file is not added to the project, but is generated when the "Add-Migration" command is called for the first time.
Syntax: Enable-Migrations
2. Add-Migration
Note:Based on the changes made to the model since the previous migration, a base frame is built for the next migration.
Syntax: Add-Migration "[Name]"
Name: Migration display Name, which will constitute the generated migration file Name with the current generated file Timestamp
Iii. Update-DataBase
Note:Migrate all pending applications and databases
Syntax: Update-Database-[Option]
Option: Vcrbose displays the SQL statement executed by the migration on the console
TargetMigration: [Name] migration to a specific version. If you need to roll back to an empty database, you can write [Name] as $ InitialDatabase
Script is a Script generated for migration without execution.
SourceMigration: [Name] source migration
Iv. Automatic migration
Note:When deploying an application, you want to automatically upgrade the database through a suspended migration when the application starts.
Code: Database. SetInitializer (new MigrateDatabaseToLatestVersion <DbContext, Configuration> ());
[The above collection is easy to use, Do not spray]