![](/img/trans.png)
[英]How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations?
[英]Add-Migration while there are explicit migrations pending
因此,當我沒有DB同步時(直到最新的遷移,實際上根本沒有DB)並且已經對我的模型進行了實質性更改,我在嘗試生成遷移時遇到了一個基本問題。
這是具體細節:
我意識到在#5失敗后我現在可以運行#4。 然后重新嘗試#5和voilá。
我的問題是,如果這是解決這種愚蠢局面的預期方法。
我會使用以下方法。
首先,您需要應用遷移並指定最后一個。
PM> Update-Database -TargetMigration AnyMigrationName
# It updates database to a migration named "AnyMigrationName"
# This will apply migrations if the target hasn't been applied or roll back migrations
# if it has
更新本地數據庫后,只需添加新遷移即可。
PM> Add-Migration NewMigrationName
# it scaffolds a new migration named "NewMigrationName"
尋找一個很好的參考我發現這些關於EF遷移的博客文章可以幫助你很多。 它們涵蓋了許多問題,特別是EF遷移和合並沖突以及EF遷移命令參考 。
當您有許多待遷移的遷移時,會顯示此錯誤。
如果您不需要現有遷移,請首先刪除(排除)遷移文件夾上的所有遷移,然后添加新遷移。
Add-Migration new
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.