gpt4 book ai didi

asp.net - 启用迁移到另一个上下文?

转载 作者:行者123 更新时间:2023-12-01 06:35:54 24 4
gpt4 key购买 nike

我在一个应用程序中有两个 DBContext 类。 MyMvcContext和自动生成 UserContext .

我一直在使用 MyMvcContext 开发一个网络应用程序一阵子。现在我需要修改 UserProfile 的类这是在上下文 UsersContex .我尝试将类更改迁移到数据库并运行以下命令。但是,我在运行 Enable-Migrations -ContextTypeName MyMvc.Models.UsersContext 时收到错误消息?

PM> Enable-Migrations 
More than one context type was found in the assembly 'MyMvc'.
To enable migrations for MyMvc.Models.UsersContext, use Enable-Migrations -ContextTypeName MyMvc.Models.UsersContext.
To enable migrations for MyMvc.Models.MyMvcContext, use Enable-Migrations -ContextTypeName MyMvc.Models.MyMvcContext.
PM> Enable-Migrations -ContextTypeName MyMvc.Models.UsersContext
Migrations have already been enabled in project 'MyMvc'. To overwrite the existing migrations configuration, use the -Force parameter.

更新:
我应该找到并替换所有 UsersContextMyMvcContext在我的项目文件中?

最佳答案

为项目启用迁移后。你不使用Update-Database - 见 Entity Framework Migrations

这就是您收到错误消息的原因,迁移已经启用...一旦启用,您就可以使用上述命令更新数据库。

关于asp.net - 启用迁移到另一个上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14947839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com