【发布时间】:2015-04-05 13:16:58
【问题描述】:
最近我决定将实体框架用于个人项目。 从我的 Visual Studio 2013 社区版并使用 NuGet 我安装了最新版本的框架(nuget 版本 2.8.60318.734 和实体框架 6.1.3)
一切似乎都正常我能够执行简单的 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).”
似乎是一个适当的错误消息,我只需要启用迁移。 切换到Package Manager Console,有一条鲜红色背景的消息
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
嗯,有点问题,我猜框架的某些需要的部分没有正确安装,但让我们检查一下文件。文件存在,内容似乎还可以。
好吧,让我们尝试重新安装它,以防万一第一次出现问题。使用 NuGet 我尝试卸载并重新安装。
检查包管理器控制台,又是同样可怕的错误!
嗯,让我们尝试从包管理器控制台进行卸载/重新安装。又是同样的错误!
在花了更多时间尝试谷歌类似的问题后,我遇到了一个描述类似问题的人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.
就是这样!!方括号是罪魁祸首
所以底线是这样的,如果您使用的是实体框架不要在路径中使用 [ ]。
【问题讨论】:
标签: c# .net entity-framework visual-studio visual-studio-2013