public class ApplicationUser:IdentityUser
{
// ForeignKey設置為可選
[ForeignKey("Hometown")]
public int? HometownId { get; set; }
public Hometown Hometown { get; set; }
}
為什麼這樣執行migration:
dotnet ef migrations add CreateForeignKey
dotnet ef database update
後HometownId的欄位還是不能為空Null?
改成這樣:
public class ApplicationUser:IdentityUser
{
public int? HometownId { get; set; }
// ForeignKey設置為可選
[ForeignKey("HometownId")]
public virtual Hometown Hometown { get; set; }
}