2015-04-05 150 views
0

最近,我決定使用實體框架進行個人項目。 從我的Visual Studio 2013社區版和使用NuGet我安裝了最新版本的框架(nuget版本2.8.60318.734和實體框架6.1.3)實體框架導入模塊:指定模塊'... EntityFramework.psd1'未加載

一切似乎工作OK我能夠執行簡單的CRUD操作,直到我需要更新我的模型。 它之後,我當然得到了錯誤信息:

「Additional information: The model backing the 'MyContext' context has changed since 
the database was created. Consider using Code First Migrations to update the database 
(http://go.microsoft.com/fwlink/?LinkId=238269).」 

似乎是一個適當的錯誤消息,我只需要啓用的遷移。 切換到包管理器控制檯,並有在明亮的紅色背景的消息

PM> Import-Module : The specified module 'D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\EntityFramework.psd1' was not loaded because 
no valid module file was found in any module directory. 
At D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\init.ps1:8 char:14 
+ Import-Module <<<< (Join-Path $toolsPath EntityFramework.psd1) 
    + CategoryInfo   : ResourceUnavailable: (D:\[MyProjects]...yFramework.psd1:String) [Import-Module], FileNotFoundException 
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand 

Hmmmm什麼是錯的,我猜框架的一些必要的部分未正確安裝,但讓我們檢查文件。該文件存在,內容似乎確定。

好吧,讓我們試着重新安裝它,以防萬一第一次出現問題。使用NuGet我試圖卸載並重新安裝。

檢查軟件包管理器控制檯,同樣可怕的錯誤!

嗯,讓我們嘗試從軟件包管理器控制檯執行卸載/重新安裝。同樣的錯誤!

花費更多時間嘗試Google類似的問題後,我遇到了某人描述類似的問題Entity Framework with NuGet - Import-Module error in init.ps1試過...沒有運氣。

那麼究竟發生了什麼?在一個尤里卡時刻,我認爲......堅持下去,我的項目路線是什麼?

D:\[MyProjects]\[ProofOfConcept]\…. 

難道是嗎?方括號是原因嗎?

創建一個項目複製到一個簡單的路徑(d:\ tmp \ myProject)啓動Visual Studio,進入包管理控制檯,...。沒有錯誤!

Enable-Migrations 
PM> Enable-Migrations 
Checking if the context targets an existing database... 
Detected database created with a database initializer. Scaffolded migration '201504051040353_InitialCreate' corresponding to existing database. To use an automatic migration instead, delete the Migrations folder and re-run Enable-Migrations specifying the -EnableAutomaticMigrations parameter. 
Code First Migrations enabled for project EntityFrameworkInvalidFilepath. 

就是這樣!方括號是罪魁禍首

所以底線是這樣的,如果你使用的是實體框架不要在路徑中使用[]

回答

1

我最近和NuGet沒有正確安裝EF 6.1.3相同的問題,因爲EntityFramework.psd1文件沒有被導入。通過Visual Studio卸載和重新安裝EF沒有幫助。

我的工作是退出VS,導航到'[Project Root Directory] ​​\ packages'並刪除EntityFramework6.1.3目錄。當您重新啓動VS並進入包管理器控制檯時,它會通知您有缺少模塊並詢問您是否要導入它們。當您點擊'重新加載'時,EF 6.1.3已正確安裝在'packages'目錄下。

在我的情況下,我使用2015RC,它有a lot of issues with EF migrations