2016-07-02 141 views
6

在此之後Microsoft Tutorial當我運行在從同一個教程中,我得到以下錯誤創建VS2015項目PM> Add-Migration MyFirstMigration命令,我解決不了:ASP.NET核心EF添加遷移命令不工作

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands. 

注意點

  1. 我使用的是我使用Individual User Account驗證,而不是No Authentication在教程中使用的例外上面的教程。
  2. 我已發佈最新版本ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
  3. 這是一個新創建的項目。沒有其他的DbContext手動安裝
+1

錯誤文本描述了原因,你應該怎麼做。 – dotctor

回答

12

運行以下命令(從this article獲得)和@Maverik響應(從計算器here)和@doctor建議上面幫我解決了問題。謝謝大家的幫助:

PM> Add-Migration MyFirstMigration -Context BloggingContext 
+3

與此同時,'-Context'從我可以測試的狀態變爲'-c' – alexo

1

因爲你在你的解決方案中有兩個DbContext。首先是在創建項目(ApplicationDbContext)時創建的默認值,其次是您的EF DbContext。 解決方法在錯誤消息中描述,只是指定您的EF DbContext

0

錯誤清楚地解釋了提及 - 與db上下文名稱的情況下,如果多於一個DbContext。所以試着提一下你的DbContext名字。

dotnet ef migrations add Initial --context SampleDbContext 

希望這會有所幫助。