简体   繁体   English

未找到添加迁移和更新数据库命令 Visual Studio 2015

[英]Add-Migration and Update-Database commands not found Visual Studio 2015

I've seen similar questions to this and I've tried every posted solution to all of them.我见过与此类似的问题,并且我已经尝试了所有已发布的解决方案。 I've been trying to fix this seemingly simple problem for the past two days and have gotten nowhere.在过去的两天里,我一直试图解决这个看似简单的问题,但一无所获。 When I try to run Add-Migration or Update-Database from the Package Manager Console, I get the following error:当我尝试从包管理器控制台运行 Add-Migration 或 Update-Database 时,出现以下错误:

Update-Database : The term 'Update-Database' is not recognized as the name of a cmdlet, function, script file, or operable program.更新数据库:术语“更新数据库”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 At line:1 char:1 + Update-Database + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException在第 1 行字符:1 + 更新数据库 + ~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Update-Database:String) [], CommandNotFoundException +fullyQualifiedErrorId : CommandNotFoundException

or或者

Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program.添加迁移:术语“添加迁移”不被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 At line:1 char:1 + Add-Migration TestMigration + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException在 line:1 char:1 + Add-Migration TestMigration + ~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException +fullyQualifiedErrorId : CommandNotFoundException

Here is my project.json:这是我的 project.json:

{
  "dependencies": {
    "Braintree": "3.5.0",
    "CoreCompat.System.Drawing": "1.0.0-beta006",
    "Google.Apis.Auth": "1.20.0",
    "Google.Apis.Oauth2.v2": "1.20.0.672",
    "MailKit": "1.10.1",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "RazorLight": "1.0.0-rc1",
    "RazorLight.MVC": "1.0.3",
    "SendGrid.NetCore": "1.0.0-rtm-00002",
    "Tinify": "1.5.0"
  },
  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
  "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

I've tried running dotnet restore , restarting Visual Studio, running Visual Studio as administrator, restarting my computer, deleting the dependencies to EntityFramework and re-adding them.我试过运行dotnet restore ,重新启动 Visual Studio,以管理员身份运行 Visual Studio,重新启动我的计算机,删除对 EntityFramework 的依赖项并重新添加它们。

I need to be able to run Add-Migration to update my SQL database, any help would be appreciated.我需要能够运行 Add-Migration 来更新我的 SQL 数据库,任何帮助将不胜感激。

EDIT:编辑:

I ended up just creating a new project, installing all of the dependencies again and copying my code over.我最终只是创建了一个新项目,再次安装了所有依赖项并复制了我的代码。 That did the trick, but an actual solution could still help, and help others with a similar problem.这确实奏效了,但实际的解决方案仍然可以帮助解决类似问题的其他人。

Just install Microsoft.EntityFrameworkCore.Tools package from nuget:只需从 nuget 安装Microsoft.EntityFrameworkCore.Tools包:

Install-Package Microsoft.EntityFrameworkCore.Tools -Version 3.1.1安装包 Microsoft.EntityFrameworkCore.Tools -Version 3.1.1

You can also use this link to install the latest version: Nuget package link您也可以使用此链接安装最新版本: Nuget 包链接

Copied from Nasir Jafarzadeh复制自Nasir Jafarzadeh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Nuget 命令上使用 Add-Migration 更新数据库? - How do i update-database using Add-Migration on Nuget command? visual studio 的 package 管理控制台中的添加迁移未在我的本地 sql 服务器中创建数据库 - Add-Migration in package management console of visual studio not creating database in my local sql server 实体框架迁移更新数据库成功,但未添加数据库列 - Entity Framework Migration update-database succeeded but database column is not added 代码首次迁移中更新数据库命令出错 - Error in update-database command in code first migration 无法在Visual Studio 2015中将表添加到SQL Server数据库 - Can't add table to SQL Server database in Visual Studio 2015 使用MS Visual Studio 2015添加本地SQL数据库时出错 - Error to add local sql database with MS Visual Studio 2015 在Visual Studio 2015中创建数据库 - Creating Database in Visual Studio 2015 在MVC迁移中,我无法从一种解决方案更新数据库,但可以从另一种解决方案更新数据库 - In MVC Migration, I can't update-database from one solution but can do it from another 由于包的不兼容性,添加迁移失败 - add-migration fails due to incompatability of packages .net核心EntityFramework“添加迁移”无效 - .net core EntityFramework “Add-Migration” not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM