0
我啓用的Code First遷移,但一段時間後,我改變了模特屬性,所以當我跑給出以下錯誤的應用程序。改變模式後的Code First遷移
無效的列名等等......因爲遷移後,我改變了模型。
到目前爲止,我明白的問題是,我更新了模型,但這些變化並不適用於數據庫中的表...好心幫我解決it..means模特屬性和數據庫列不匹配
遷移已啓用。 我將自動遷移設置爲true,但我無法工作。
public class Floor
{
public int FloorID { get; set; }
public string Name { get; set; }
public virtual ICollection<Room> Rooms { get; set;}
}
public class Room
{
public int RoomID { get; set; }
public string Name { get; set; }
[Display(Name ="Room Rent")]
public decimal Rent { get; set; }
[Display(Name="Floor")]
public int FloorID { get; set; }
public int Seater { get; set; }
[Display(Name="Attach Bathroom")]
public Boolean AttachedBathRoom { get; set; }
public virtual Floor Floor { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
public class Student
{
public int StudentID { get; set; }
public string Name { get; set; }
public int CNIC { get; set; }
public int Phone { get; set; }
[Display(Name="Floor")]
public int FloorID { get; set; }
[Display(Name ="Room No")]
public int RoomID { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public string Department { get; set; }
public virtual Floor Floor { get; set; }
public virtual Room Room { get; set; }
}
我執行你給出的命令後出現以下錯誤「:
然後使用此命令更新數據庫爲表'Rooms'指定多個標識列,每個表只允許一個標識列「。在包管理器中。 –
如果我理解正確的話,你在房間FloorId是一個外鍵,對不對? –
是FloorID是foriegn鍵。 –