【问题标题】:How to add A migration if you have more DbContexts in dotnet core 2?如果在 dotnet core 2 中有更多 DbContexts,如何添加迁移?
【发布时间】:2020-01-08 09:14:54
【问题描述】:

我正在使用 dotnet core 2 和 Visual Studio 2019,并且我有几个数据库上下文。但我想向 MedicalDbContext 添加迁移。而且我还有更多的默认项目。但正确的默认项目是 HepEngine。所以我在包管理器中选择该项目作为默认项目。

并在命令提示符下:PM>Add-Migration add-echeq-alert-action-extraProperty -c medicalDbContext -s

然后我得到这个错误:

Add-Migration : Missing an argument for parameter 'StartupProject'. Specify a parameter of type 'System.String' and try again.
At line:1 char:72
+ ... Migration add-echeq-alert-action-extraProperty -c medicalDbContext -s
+                                                                        ~~
    + CategoryInfo          : InvalidArgument: (:) [Add-Migration], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Add-Migration

那么我必须改变什么?谢谢

【问题讨论】:

标签: visual-studio asp.net-core entity-framework-migrations package-managers


【解决方案1】:

如果您有多个 DataContext,则需要指定应为哪个上下文创建迁移。对于我的项目,我正在使用此代码

add-migration YOURMIGRATIONNAME -context MyDbContext

MyDbContext 是您的上下文名称。

您可以找到文档here

【讨论】:

    猜你喜欢
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    • 2020-01-23
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多