I have looked at all the similar questions on this topic but none seem to work for me. I don't know exactly why I am getting the below error when I try to run these two commands: add-migration
and then update-database
.
Cannot insert the value NULL into column 'StudentId', table 'aspnet-JavaWebsiteProject-20171006053028.dbo.Groups'; column does not allow nulls. UPDATE fails. The statement has been terminated.
I am using Entity Framework v6.2.0
. I have three simple models below:
public class Student
{
public int Id { get; set; }
public string UserId { get; set; }
[EmailAddress]
public string Email { get; set; }
}
Teacher model:
public class Teacher
{
public int Id { get; set; }
public string UserId { get; set; }
[EmailAddress]
public string Email { get; set; }
}
//Group model:
public class Group
{
public int Id { get; set; }
[Required]
public int StudentId { get; set; }
public Student Student { get; set; }
[Required]
public int TeacherId { get; set; }
public Teacher Teacher { get; set; }
}
Can anyone guide me on what I might be doing wrong or how I can fix this error?
Thank you