[英]“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 管理器并使用命令“启用迁移”也不起作用。
The following helped me to add the missing tools to .net core 3.1以下帮助我将缺少的工具添加到 .net core 3.1
Install-Package Microsoft.EntityFrameworkCore.Tools安装包 Microsoft.EntityFrameworkCore.Tools
Update-Package Microsoft.EntityFrameworkCore.Tools更新包 Microsoft.EntityFrameworkCore.Tools
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 时:
IF you created more than one model (to create multiple tables in your database), follow these next steps also:如果您创建了多个 model(在您的数据库中创建多个表),还请按照以下步骤操作:
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):
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 ,新类的文件名以时间戳开头)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:要查看数据库表:
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.