最近,我决定使用实体框架进行个人项目。 从我的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.
就是这样!方括号是罪魁祸首
所以底线是这样的,如果你使用的是实体框架不要在路径中使用[]。