【问题标题】:Issue trying to Scaffold-DbContext尝试使用 Scaffold-DbContext 的问题
【发布时间】: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


【解决方案1】:

在对所有键进行三次检查后,确实有第二个键用于导致问题的同一关系。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2018-05-22
    • 1970-01-01
    • 2020-10-15
    相关资源
    最近更新 更多