0
我有兩個模型類,我想要做一對一的關係。當我做遷移,我得到一個錯誤:代碼第一對一外鍵
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Uzytkownik_dbo.UserProfile_UserId". The conflict occurred in database "db_wydarzenia", table "dbo.UserProfile", column '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表中刪除所有數據,它的去。
這不是一個問題。我必須從uzytkownik表中刪除所有數據。感謝您的幫助;) – user1031034 2013-04-04 11:20:45
但您沒有一對一 - 您擁有的是一對多 - 這是唯一真正解決問題 – NSGaga 2013-04-04 11:21:36
是的,您有權利。 – user1031034 2013-04-04 11:23:18