【发布时间】:2022-01-14 10:52:45
【问题描述】:
当我尝试从 MSSQL 服务器连接 Scaffold-DbContext 时,我能够正常连接,但我收到一个关于几周前从数据库中删除的表中的外键的错误。它看到的表称为 ServiceTicket,我有一个类似的表名为 ServiceTickets,并且我已确保所有外键都已正确设置。
我得到的确切错误:
The foreign key {'ServiceTypeId'} cannot be added to the entity type 'ServiceTicket' because a foreign key on the same properties already exists on entity type 'ServiceTicket' and also targets the key {'ServiceTypeId'} on 'ServiceType'.
我们在 db 中实际拥有的表名是 ServiceTickets 和 ServiceType
我也已经尝试删除并重新创建关系
【问题讨论】:
-
EF 可能正在复数您的表名。
-
发布确切的错误、相关的表名和外键定义
标签: c# sql-server entity-framework entity-framework-core