Entity Framework常用命令
- Enable-Migrations 启用Migration数据迁移
- Add-Migration migrationname 为挂起的Model变化添加迁移脚本
- Update-Database –TargetMigration:migrationname 回滚到指定数据库
- Update-Database 将挂起的迁移更新到数据库
- Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: AddPostAbstract 生产迁移sql脚本
- get-help Update-Database -detailed查看Add-Migration的详细用法。
若要查看示例,请键入: "get-help Update-Database -examples".
有关详细信息,请键入: "get-help Update-Database -detailed".
若要获取技术信息,请键入: "get-help Update-Database -full".
-------------------------- 示例 1 --------------------------
Update-Database
# Update the database to the latest migration
-------------------------- 示例 2 --------------------------
Update-Database -TargetMigration Second
# Update database to a migration named "Second"
# This will apply migrations if the target hasn't been applied or roll back migration
s
# if it has
-------------------------- 示例 3 --------------------------
Update-Database -Script
# Generate a script to update the database from it's current state to the latest mig
ration
-------------------------- 示例 4 --------------------------
Update-Database -Script -SourceMigration Second -TargetMigration First
# Generate a script to migrate the database from a specified start migration
# named "Second" to a specified target migration named "First"
-------------------------- 示例 5 --------------------------
Update-Database -Script -SourceMigration $InitialDatabase
# Generate a script that can upgrade a database currently at any version to the lates
t version.
# The generated script includes logic to check the __MigrationsHistory table and only
apply changes
# that haven't been previously applied.
-------------------------- 示例 6 --------------------------
Update-Database -TargetMigration $InitialDatabase
# Runs the Down method to roll-back any migrations that have been applied to the data
base