术语“更新 - 数据库”未被识别为cmdlet的名称

时间:2012-03-12 21:20:17

标签: entity-framework ef-code-first ef-migrations entity-framework-5

我正在使用EF5 beta1,而我之前能够运行“更新数据库”。现在我关闭了Visual Studio,我无法让它运行。我收到以下错误:

  

术语“更新 - 数据库”未被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。   在行:1字符:16   + Update-Database<<<< -verbose       + CategoryInfo:ObjectNotFound:(Update-Database:String)[],CommandNotFoundException       + FullyQualifiedErrorId:CommandNotFoundException

我尝试重新安装EF5b1并且虽然成功(已经安装),但“更新数据库”仍无效。

任何人都可以帮忙???

27 个答案:

答案 0 :(得分:159)

我最近多次遇到这个问题。我发现有效的解决方案是关闭软件包管理器控制台,关闭Visual Studio然后重新打开它们。重启也在大部分时间都有效,但并非总是如此。

答案 1 :(得分:48)

如果您使用实体框架:

  

错误消息:   “错误消息(来自PMC中的Update-Database命令):   术语“更新 - 数据库”未被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。“

     

<强>解决方案:   “退出Visual Studio。重新打开项目并重试。”

有关详细信息,请访问:Advanced Entity Framework 6 Scenarios for an MVC 5 Web Application (12 of 12)

希望这会有所帮助......

答案 2 :(得分:20)

有时当我加载VS时,我在包管理器控制台中看到了这一点:

  

值不能为空。

     

参数名称:path1

我不知道是什么导致了这一点,但似乎在Powershell控制台启动期间出现问题,这会中断特定模块的注册,例如EF powershell扩展。您可以手动加载它:

Import-Module .\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1

确保将6.1.1替换为当前版本的Entity Framework。

答案 3 :(得分:16)

重新安装nuget包为我解决了这个问题

即执行

Install-Package EntityFramework -Version 5.0.0
包管理器中的

答案 4 :(得分:8)

只需重新启动Visual Studio,它就能解决问题。适合我。

答案 5 :(得分:7)

如果未正确安装EF工具,您将收到此错误。

在Nuget包管理器中尝试以下命令 //卸载并安装相同版本的EF

Update-Package "EntityFramework" -reinstall

如果您仍面临同样的问题。  创建一个新的Web项目并在nuget中运行以下命令。

  

(注意:无需在同一解决方案中创建新项目或   同一地点。)

//这会将EF更新到最新版本(包括工具)  //如果您想使用特定版本,请使用-version标记。

Update-Package "EntityFramework"

完成此操作后,请删除原始项目,然后删除新创建的项目。

答案 6 :(得分:4)

我遇到了同样的问题,它的来源是我的路径名,我的路径上有一个带直括号的目录名,如下所示:C:\[PROJ]\TestApp

当我删除括号时,C:\PROJ\TestApp,它开始正常工作......

答案 7 :(得分:4)

对我来说问题是 Nuget版本

  1. 卸载Nuget Package Manager。
  2. 重新启动Visual Studio。
  3. 安装了新版本的Nuget Package Manager。
  4. 然后重新启动Visual Studio。

答案 8 :(得分:4)

Just ReOpen visual studio对我有用

答案 9 :(得分:2)

我通过卸载并重新安装“ Microsoft.EntityFrameworkCore.Microsoft”和“ Microsoft.EntityFrameworkCore.Tools”解决了

答案 10 :(得分:1)

当您直接从文件资源管理器中打开项目时,似乎会发生此问题。首先尝试启动VS然后打开项目 - 为我工作。我猜这是关于路径的访问。

答案 11 :(得分:0)

安装Microsoft.EntityFrameworkCore.Tools为我解决了该问题,使用了nuget包

答案 12 :(得分:0)

我在VS 2019中存在一个使用EntityFramework 6.3.0的现有项目的问题。在一段时间内,该项目对其版本进行了一些奇怪的更改,并且没有任何效果。我相信我尝试了这里列出的所有建议都没有运气。

最后,更新到EntityFramework的预发行版本(当前为6.4.0-preview3-19553-01)确实可以通过在程序包管理器控制台中运行此问题来解决此问题:Update-Package EntityFramework -prerelease。我希望这个版本在接下来的几周内正式发布时能够正常运行。

答案 13 :(得分:0)

在我的情况下,重新启动Visual Studio (很多次)不起作用,然后当我在其他地方查看时,在输出终端上发现了一条消息:

  

当前的.NET SDK不支持定位.NET Core 2.2。要么   目标.NET Core 2.1或更低版本,或使用的.NET SDK版本   支持.NET Core 2.2。

所以我安装了所需的.NET Core版本,命令成功运行。

答案 14 :(得分:0)

对于使用.Net Core和EntityFrameworkCore的任何人:

您将需要安装Microsoft.EntityFrameworkCore.Tools软件包来解决此问题。

在此处了解更多信息:https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

答案 15 :(得分:0)

就我而言:

  • 重新加载项目没有帮助
  • 重新启动VS没有帮助
  • 重新启动计算机没有帮助
  • Reinstal EF没有帮助

但是我发现一个article的建议是使用PM Conole手动导入丢失的EF软件包:

<!-- Developed @ the University of Advancing Technology for use in UAT courses. --> <html> <head> <title>Virtual Pet</title> <script> // Virtual Pet Stats and starting values // TODO: Change the name of your Virtual Pet on the line below. var petName = "Virtual Pet"; var currentHealth = 60; var maxHealth = 100; var petStatus = "healthy"; var tiredness = 60; var maxTiredness = 100; var hunger = 60; var maxHunger = 100; // TODO: Add more Virtual Pet stats that will be modified by your functions // Increases the current health of the Virtual Pet until it is maxed out. function exercise() { currentHealth = currentHealth + 5; if(currentHealth > maxHealth) { currentHealth = maxHealth; } // Update the display after an action has occurred. updateDisplay(); } function sleep(){ var sleepamount = prompt("How many minutes would you like to sleep?"); tiredness = sleepamount + tiredness; if (tiredness >= 100) { tiredness = 100; } // Update the display after an action has occurred. updateDisplay(); } function checkHunger(){ var feed = prompt("How many snacks do you want to eat?"); hunger = feed + hunger; if (hunger >= 100) { hunger = 100; } // Update the display after an action has occurred. updateDisplay(); } // TODO: Write new functions that will process and modify the new stats you have created. (The majority of your new code should go here.) // Modifies any stats that automatically change every few seconds. // (For example, health decreases every few seconds so the play needs to occationally exercise their Virtual Pet) function changesOverTime() { currentHealth = currentHealth - 4; tiredness = tiredness - 4; hunger = hunger - 4; // TODO: Add in other changes to the Virtual Pet stats that occur on a regular basis. } // Checks the pet's health and modifies the status accordingly function checkHealth() { if(currentHealth <= 0 ) { petStatus = "Dead"; currentHealth = 0; } //TODO (Optional): Add other health status checks (For example, sick if health < 15) } function checkStarved() { if(hunger <= 0 ){ petStatus = "Dead"; hunger = 0; } else if (hunger >= 30 && hunger <= 75) { petStatus = "Hungry"; //TODO (Optional): Add other health status checks (For example, sick if health < 15) } } // Displays a Title to the screen for your Virtual Pet game function displayTitle() { // TODO (Optional): Create your own title } // Displays the current pet stats to the screen. function displayPetStats() { document.write("<h2>" + petName + " Status: " + petStatus + "</h2>"); document.write("<p>Health = " + currentHealth + "&nbsp;&nbsp;&nbsp;Max Health = " + maxHealth + "</p>"); document.write("<p>Hunger = " + hunger + "&nbsp;&nbsp;&nbsp;Max Hunger = " + maxHunger + "</p>"); document.write("<p>Tiredness = " + tiredness + "&nbsp;&nbsp;&nbsp;Max Tiredness = " + maxTiredness + "</p>"); // TODO: Add the display of new Virtual Pet stats here document.close(); } // Displays the buttons to the screen enabling the user to interact with their virtual pet. function displayUserOptions() { if(petStatus != "Dead") { document.write("<button onclick='exercise()'>Exercise</button>"); document.write("<button onclick='sleep()'>Sleep</button>"); document.write("<button onclick='checkHunger()'>Feed</button>"); // TODO: Create buttons for other actions } } // Calls all the functions that display information to the screen. function updateDisplay() { displayTitle(); displayUserOptions(); displayPetStats(); } // This function executes the game and manages the passing of time. function gameLoop(timestamp) { if(timestamp > last_iteration + time_interval) { last_iteration = timestamp; changesOverTime(); checkHealth(); checkStarved() // TODO: Check other Virtual Pet stats and update the petStatus accordingly // After all stats updates are done, update/recreate the display updateDisplay(); } // Life continues unless the Virtual Pet is dead (health <= 0) if(petStatus != "Dead") { // Executes the gameLoop function once again. requestAnimationFrame(gameLoop); } } // Other global variables that control the timing of the game. var time_interval = 5000; var last_iteration = 0; </script> </head> <body> <h1>My Virtual Pet!</h1> <!-- Initiate the gameLoop for the first time.--> <button onclick='gameLoop()'>Bring my Virtual Pet to Life!</button> </body> </html>

这个解决方案解决了我的问题。

答案 16 :(得分:0)

在我意外地使用Visual Studio 2015而不是2017打开Visual Studio解决方案之后,我也遇到了同样的问题。在此之前,项目工作得很好。这是一个使用EF 5.0而不是EF Core的较旧项目。

我尝试了所有建议的操作-无数次重新启动Visual Studio,清理了NuGet缓存,删除了packages文件夹中的所有内容,为该项目重新安装了EF 5-不好,无法识别添加迁移。如果我将EF升级到6,它将开始识别命令,但是我还不想升级。因此,当我恢复到EF 5时,问题又回来了。

最后拯救我的唯一方法是执行以下操作:

  • 关闭Visual Studio
  • 从“包”文件夹中删除所有内容
  • 删除解决方案根目录中的.vs文件夹。此文件夹通常是隐藏的,您必须打开“显示隐藏的文件和文件夹”设置,或选中“视图”选项卡中的“隐藏的项目”
  • 启动Visual Studio并打开您的解决方案。它将要求还原NuGet软件包,并同意。

现在EF命令终于再次开始工作。

答案 17 :(得分:0)

我发现这是由于包装破损造成的。我已经安装了Automapper。当我尝试安装另一个软件包时,很明显这个软件包已经损坏了。

删除损坏的包解决了这个问题。

然后您可以重新安装automapper。问题是版本5.4,我现在很高兴6.0。

答案 18 :(得分:0)

对我来说,简单的解决方法是确保更新和数据库之间有破折号,例如:update-database,并使用小写字母。可能是偶然的,但是当我在Packet Manager控制台中执行此操作时,数据库实际上已更新,并且收到了完成消息,而不是not recognized as the name of a cmdlet, function, script file错误。

答案 19 :(得分:0)

我在Visual Studio 2015中遇到此问题,并通过更新Nuget版本解决了这个问题。

工具 - &gt;扩展程序和更新 - &gt;更新 - &gt; Visual Studio Gallery

答案 20 :(得分:0)

我通过更新Package Manager控制台解决了这个问题。

我没有在软件包管理器控制台中获取Update-Database。然后我重启几次。还要重新启动Windows。

然后我从nuget下载新的,然后它就解决了。

答案 21 :(得分:0)

对我来说,事实证明我的项目上没有安装EntityFramework核心(因为我从空白项目开始)。因此,安装 EntityFramework 包解决了这个问题。有时,如果EntityFramework安装失败,则尝试逐个安装单个软件包

E.g。

Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design
Microsoft.EntityFrameworkCore.Tools

答案 22 :(得分:0)

如果其他答案不起作用(VS 2017):清除NuGet缓存,重新启动VS,然后恢复软件包。

答案 23 :(得分:0)

恢复NuGet包没有帮助我。所以我不得不重新安装包管理器 - https://visualstudiogallery.msdn.microsoft.com/4ec1526c-4a8c-4a84-b702-b21a8f5293ca 可能对某人有帮助

答案 24 :(得分:0)

就我而言,我做了以下事情: - 单击程序包管理器控制台顶部的“恢复”按钮,恢复丢失的NuGet程序包 - 重新启动Visual Studio - 运行“update-databse”

答案 25 :(得分:-1)

对我来说问题是Nuget版本。

我删除并重新安装了Nuget,然后重新启动Visual Studio,然后全部开始工作。

答案 26 :(得分:-1)

我也有同样的问题,但使用 SQLPS 的 Delete-SqlDatabase。

就我而言,我试图调用我在代码中声明和使用的函数 Delete-SqlDatabase。

我犯的错误是调用了下面的函数。

您在 powershell 中看到为了使函数可见,您必须在顶部声明它。 main 函数应该是最后一部分。

这是一件多么愚蠢的事情。我相信你会在一天之内解决这个问题。

我知道这个踏板太旧了,但它可能会帮助像我这样可以节省一个小时时间的其他人。