【发布时间】:2015-12-25 21:08:34
【问题描述】:
虽然我要添加迁移,但没关系,但是当我要运行更新数据库时,我在包管理器控制台中遇到这种类型的错误
ALTER TABLE 语句与 FOREIGN KEY 约束“FK_dbo.ServiceTypes_dbo.Services_ServiceTypeID”冲突。冲突发生在数据库“Otaidea”、表“dbo.Services”、列“ServicesID”中。
我的两个模型:
public class Services
{
[Key]
public int ServicesID { get; set; }
[DisplayName("Register Date")]
public DateTime RegisterDate { get; set; }
public int ServiceTypeID { get; set; }
public string ApplicationUserID { get; set; }
public virtual ServiceType ServiceType { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
我的另一个表:
public class ServiceType
{
[ForeignKey("Services")]
public int ServiceTypeID { get; set; }
public string NAME { get; set; }
public virtual Services Services { get; set; }
}
【问题讨论】:
-
ForeignKey("Services") 必须进入服务实体中,位于 ServiceTypeID 属性上方
-
我不明白你想说什么请你解释一下我是新人
-
服务有 ServiceType。正确的?因此,您不需要在 ServiceType 中引用服务。您需要在 Service 中引用 ServiceType,并从 ServiceType 中删除 ForeignKey
-
你能帮我重写这两个类吗,因为兄弟我英语太周了。
标签: entity-framework entity-framework-migrations