简体   繁体   English

“'add-migration' 一词未被识别为 cmdlet 的名称”Visual Studio 2019

[英]“the term 'add-migration' is not recognized as the name of a cmdlet” visual studio 2019

enter image description here在此处输入图像描述
在此处输入图像描述

I'm trying to use entity frame work core and have a fresh asp.net core project open.我正在尝试使用实体框架工作核心并打开一个新的 asp.net 核心项目。 When i attempt to install Microsoft.EntityFrameworkCore.SqlServer through nuget package manager i get the following error.当我尝试通过 nuget package 管理器安装 Microsoft.EntityFrameworkCore.SqlServer 时,我收到以下错误。

Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 is not compatible with net461 (.NETFramework,Version=v4.6.1). Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 与 net461 (.NETFramework,Version=v4.6.1) 不兼容。 Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1) Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 支持:netstandard2.1 (.NETStandard,Version=v2.1)

When i click this i get sent to.csproj file.当我点击这个时,我会被发送到 .csproj 文件。

In that file i changed the target framework from <TargetFramework>net461</TargetFramework> to <TargetFramework>netstandard2.1 </TargetFramework> as the error implies.在该文件中,我将目标框架从<TargetFramework>net461</TargetFramework>更改为<TargetFramework>netstandard2.1 </TargetFramework> ,正如错误所暗示的那样。

Doing this gets rid of the error but when i use the command 'add-migration' in package manager console i get this error.这样做可以消除错误,但是当我在 package 管理器控制台中使用命令“add-migration”时,我得到了这个错误。

"The term 'add-migration' is not recognized as the name of a cmdlet" “术语 'add-migration' 未被识别为 cmdlet 的名称”

I'm not sure what to do going forward.我不确定接下来要做什么。 Please help.请帮忙。 I hope i've explained the issue clearly.我希望我已经清楚地解释了这个问题。

Deleting the project.assets file or updating nuget package manger and using the the command "enable-migrations" hasnt worked either.删除 project.assets 文件或更新 nuget package 管理器并使用命令“启用迁移”也不起作用。

enter image description here在此处输入图像描述
在此处输入图像描述

The following helped me to add the missing tools to .net core 3.1以下帮助我将缺少的工具添加到 .net core 3.1

  1. Install-Package Microsoft.EntityFrameworkCore.Tools安装包 Microsoft.EntityFrameworkCore.Tools

  2. Update-Package Microsoft.EntityFrameworkCore.Tools更新包 Microsoft.EntityFrameworkCore.Tools

  3. Get-Help about_EntityFrameworkCore获取关于_EntityFrameworkCore 的帮助

From this Blog从这个博客

  1. Tools工具
  2. NuGet Package Manager NuGet Package 经理
  3. Manage NuGet Package for Solution管理 NuGet Package 的解决方案
  4. Install Microsoft.EntityFrameworkCore.Tools安装 Microsoft.EntityFrameworkCore.Tools
  5. Try again再试一次

I have faced the same issue and these steps fixed it..我遇到了同样的问题,这些步骤解决了它..

1) Tools -> Nuget Package Manger -> Package Manager Settings 1) 工具 -> Nuget Package 管理器 -> Package 管理器设置

2) General Tab 2) 常规选项卡

3) Clear All NuGet Cache(s) 3) 清除所有 NuGet 缓存

4) Restart Visual Studio 4)重启Visual Studio

When adding your first migration to a new package:将您的第一次迁移添加到新的 package 时:

  1. Create the data model class (with the columns and data types for your table(s); see the Source link below for details)创建数据 model class (使用表的列和数据类型;有关详细信息,请参阅下面的源链接)
  2. Add a New Folder in the Pages directory (recommendation: use the name of your primary/parent DB Table - that is, the table that doesn't have any foreign keys)在 Pages 目录中添加一个新文件夹(建议:使用您的主/父数据库表的名称 - 即没有任何外键的表)
  3. Right-click on that new folder > Add > New Scaffolded Item > "Razor pages using Entity Framework (CRUD)" > Add右键单击该新文件夹 > 添加 > 新脚手架项目 > “使用实体框架 (CRUD) 的剃刀页面” > 添加
  4. Select your primary model class Select 您的主 model class
  5. Click "+" to add a data context class (this is the big critical ingredient, which is automated here)单击“+”以添加数据上下文 class(这是重要的关键成分,这里是自动化的)
  6. Change the Data context class name by replacing "Models" with "Data" (so it will create the database context class with the correct namespace)通过将“模型”替换为“数据”来更改数据上下文 class 名称(因此它将创建具有正确命名空间的数据库上下文 class)
  7. Click Add点击添加

IF you created more than one model (to create multiple tables in your database), follow these next steps also:如果您创建了多个 model(在您的数据库中创建多个表),还请按照以下步骤操作:

  1. Open the file: Data<YourNamespace>Context.cs打开文件:Data<YourNamespace>Context.cs
  2. Duplicate line 17 for each of your models (DB tables)为每个模型(数据库表)复制第 17 行

In all cases proceed with the 2 following commands in Package Manager Console (Tools [from menu at the top] > NuGet Package Manager > Package Manager Console): In all cases proceed with the 2 following commands in Package Manager Console (Tools [from menu at the top] > NuGet Package Manager > Package Manager Console):

  1. Add-Migration <NameYourMigration> , which will generate the migration code (creates a new class in the Migrations directory, which new class's file name begins with a timestamp) Add-Migration <NameYourMigration> ,将生成迁移代码(在 Migrations 目录中创建一个新的 class ,新类的文件名以时间戳开头)
  2. Update-Database , which will run the use the Up() method from the new class file it just created in the Migrations directory BAM! Update-Database ,它将使用刚刚在 Migrations 目录 BAM 中创建的新 class 文件中的 Up() 方法运行! You should now have (a) new database table(s) in your database!您现在应该在您的数据库中有(一个)新的数据库表!

To see the database tables:要查看数据库表:

  1. View (from menu at the top) > SQL Server Object Explorer > SQL Server > (localdb)\MSSQLLocalDB... > Databases > Context... > Tables查看(从顶部的菜单)> SQL 服务器 Object 资源管理器 > SQL 服务器 > (localdb)...\MSSQLLocalDB... > 表 > 数据库
  2. To see the data definition: double-click on the table name查看数据定义:双击表名
  3. To see the data (empty tables right now): right-click on the table name > View Data要查看数据(现在为空表):右键单击表名 > 查看数据

Source (with images, but some steps are a spread out in the tutorial): https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model来源(带有图像,但教程中已展开一些步骤): https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model

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

相关问题 术语“add-migration”未被识别为 cmdlet 的名称 - The term 'add-migration' is not recognized as the name of a cmdlet 无法识别 Visual Studio Code Entity Framework Core Add-Migration - Visual Studio Code Entity Framework Core Add-Migration not recognized 术语&#39;&#39;不被识别为cmdlet的名称, - The term ' ' is not recognized as the name of a cmdlet, 术语“Add-AzureAccount”未被识别为cmdlet,函数,脚本文件的名称 - The term 'Add-AzureAccount' is not recognized as the name of a cmdlet, function, script file 术语“ New-CsOnlineSession”不被视为cmdlet的名称 - The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet 术语“Connect-AzureAD”未被识别为 cmdlet 的名称 - The term 'Connect-AzureAD' is not recognized as the name of a cmdlet 术语“添加编号”不被视为cmdlet,函数,脚本文件或可运行程序的名称 - The term 'Add-Number' is not recognized as the name of a cmdlet, function, script file, or operable program Visual Studio 2022 中的错误添加迁移,Entity Framework Core 版本 6.06 及更低版本 - Error Add-Migration in Visual Studio 2022, Entity Framework Core Version 6.06 and lower 无法在 Visual Studio 2022 中运行添加迁移,EF6 Code First - Cannot run Add-Migration in Visual Studio 2022, EF6 Code First 如何在 Visual Studio 2015 中使用“添加迁移”命令 - How can i use “Add-Migration” command in Visual Studio 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM