#Environmental requirements
- Install-Package EntityFrameworkRequired
PS: MYSQL and ORACLE need to install the corresponding database Nuget package
#Build migration configuration
Enable-Migrations
parameter list
- -Auto builds the migration configuration with automatic migrations enabled for the project
- -ContextTypeName MyContext - Migration directory directory name Projects with multiple contexts build migration configurations
- -EnableAutomaticMigrations enable automatic migrations
public Configuration() { AutomaticMigrationsEnabled = false; // Whether to enable automatic migration }
#Add migration record
Add-Migration migration name
parameter list
- -IgnoreChanges Builds an empty migration, ignoring any pending changes detected in the current model. This can be used to create an initial, empty migration to enable migrations for existing migrations.
- -Force existing-migration-name Specifies to rebuild an existing migration.
- -ProjectName Specifies the project containing the migration configuration type to use. If omitted, the default project selected in the Package Manager Console.
- -StartUpProjectName Specifies the configuration file to use for naming the connection string. If omitted, the specified project's configuration file will be used.
- -ConfigurationTypeName Specifies the migration configuration to use. If omitted, migrations will attempt to locate a single migration configuration type item in the target.
- -ConnectionString Specifies the connection string to use, if omitted the default is used.
- -ConnectionProviderName Specifies the provider fixed name for the connection string.
- -AppDomainBaseDirectory Specifies the directory of the application domain in which to run the migration.
#Synchronize to database
Update-Database
parameter list
- -TargetMigration migration name to synchronize the database to the specified migration version
- -Script Generate script to update database from current state to latest migrations
- -Script -SourceMigration migrate A -TargetMigration migrate B Migrate named "A" to the specified target named "B"
- -Script -SourceMigration $InitialDatabase Generate a script that can upgrade a database that is currently at any version to the latest version
- -TargetMigration $InitialDatabase rolls back any migrations that have been applied to the database
- -Verbose View the executed SQL statement
- -SourceMigration specifies the name of a specific migration to use as the starting point for updates
- -Force specifies to automatically migrate the database
- -ProjectName specifies the project containing the migration configuration type
- -StartUpProjectName specifies the configuration file to use for naming the connection string
- -ConfigurationTypeName specifies the migration configuration to use
- -ConnectionStringName specifies the configuration file to connect from the application
- -ConnectionString specifies the connection string to use
- -ConnectionProviderName Specifies the provider fixed name for the connection string
#problems encountered
Problem prompt: enable-migrations failed to build.
Problem report: EF generates synchronous migration error report
Workaround: Regenerate the solution