【发布时间】:2013-03-26 05:53:57
【问题描述】:
我有两个模型类,我想在其中建立一对一的关系。当我进行迁移时,我收到一个错误:
ALTER TABLE 语句与 FOREIGN KEY 约束冲突 “FK_dbo.Uzytkownik_dbo.UserProfile_UserId”。冲突发生在 数据库“db_wydarzenia”,表“dbo.UserProfile”,列“UserId”。
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}
[Table("Uzytkownik")]
public class Uzytkownik
{
[Key]
public int UzytkownikID { get; set; }
public int UserId { get; set; }
public string Imie { get; set; }
public string Nazwisko { get; set; }
public string Telefon { get; set; }
public string Email { get; set; }
[ForeignKey("UserId")]
public UserProfile UserProfile { get; set; }
}
编辑: 问题解决了 :) 我从 uzytkownik 表中删除了所有数据,然后就可以了。
【问题讨论】:
标签: ef-code-first