我想对这个帖子做一些澄清:
Update-Database -TargetMigration:"name_of_migration"
上面所做的就是回滚所有的迁移,直到剩下指定的迁移为止。因此,如果你使用get - migrations,你发现你有A, B, C, D和E,那么使用这个命令将回滚E和D,让你到C:
Update-Database -TargetMigration:"C"
此外,除非有人有相反的意见,否则我注意到您可以使用序数值和短的-Target开关(因此,-Target与-TargetMigration相同)。如果你想要回滚所有的迁移并重新开始,你可以使用:
Update-Database -Target:0
0, above, would rollback even the FIRST migration (this is a destructive command--be sure you know what you're doing before you use it!)--something you cannot do if you use the syntax above that requires the name of the target migration (the name of the 0th migration doesn't exist before a migration is applied!). So in that case, you have to use the 0 (ordinal) value. Likewise, if you have applied migrations A, B, C, D, and E (in that order), then the ordinal 1 should refer to A, ordinal 2 should refer to B, and so on. So to rollback to B you could use either:
Update-Database -TargetMigration:"B"
or
Update-Database -TargetMigration:2
2019年10月编辑:
根据类似问题的相关回答,EF Core 1.1正确的命令是-Target, EF Core 2.0正确的命令是-Migration。