如果项目包含多个文件夹,如何使用添加迁移 [英] How to use Add-Migration if the project contains multiple folders

查看:62
本文介绍了如果项目包含多个文件夹,如何使用添加迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用DbContext Add-Migration ,但出现错误:

I would like to Add-Migration with my DbContext, but I get Error:

术语"add-migration"不被视为cmdlet,函数,脚本文件或可运行程序的名称.

问题与文件夹结构有关吗?自定义的User.cs,Role.cs和Startup.cs位于不同的文件夹中.

Is the problem related with folder structure? The customized User.cs, Role.cs and the Startup.cs are in different folders.

实体框架包含在DbContext项目文件中.

The Entity Framework is included in the DbContext project file.

我该如何解决?

推荐答案

问题与文件夹结构有关吗?

Is the problem related with folder structure?

此问题与文件夹结构无关.与 nuget包和您项目的目标框架有关.

This issue is not about the folder structure.It's about the nuget packages and you project's target framework.

Nuget软件包可以为您带来 EF框架的一部分.就像 Microsoft单元测试框架一样,我们必须使用项目中的 MSTest.TestFramework MSTest.TestAdapter 包来制作测试框架工作正常.

Nuget packages can bring the part of EF framework to you. Just like Microsoft Unit Test framework, we have to consume the MSTest.TestFramework and MSTest.TestAdapter packages in the project to make the test framework work well.

关于您的问题,最初的原因可能是您当前项目中的那些程序包未加载或不兼容.(图2中的黄色警告).

As for your issue, the original cause can be that those packages are not loaded or incompatible in your current project.(Yellow warnings in pic 2).

解决黄色警告,然后安装 Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.Tools 软件包,然后该命令应该可以使用.参见:

Resolve the yellow warnings and install the Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Tools packages, then the command should work. See:

在安装这两个软件包之前,图片中出现了红色警告.成功安装它们后,当前项目可以很好地识别该命令.

Red warnings in pic occurred before I install that two packages. After install them successfully, the command can be recognized well by current project.

建议:

如果您不熟悉如何解决nuget问题(黄色警告),请在错误列表"窗口中共享有关它的更多详细信息,您的VS版本,目标框架,错误消息...

If you're not that familiar with how to resolve nuget issues(yellow warnings), share more details about it, your VS version, target framework, error messgae in Error List window...

我还建议您创建一个新的 Asp.net核心Web应用进行测试,除了成功安装这两个软件包外,什么都不要做,然后添加迁移新项目可以识别该命令.然后,您可以确认当前项目中的nuget软件包是否有问题(导致上述问题),就像我上面所说的那样.

And also I suggest you can create a new Asp.net core web app to test it, do nothing but install those two packages successfully, then the Add-migration command can be recognized by your new project. Then you can confirm if something wrong with nuget packages in your current project that causes the issue, like what I said above.

希望它会有所帮助:)

这篇关于如果项目包含多个文件夹,如何使用添加迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆