Я пытаюсь запустить миграцию.Миграция проходит, однако, когда я пытаюсь обновить базу данных, я получаю это сообщение об ошибке
Невозможно вставить значение NULL в столбец scheduleDateAndTimeid, таблица aspnet-ScheduleWebApp-20190525082521.dbo.Students«;столбец не допускает пустых значений.ОБНОВЛЕНИЕ не удается.
У меня есть два класса моделей, один из которых называется student
, а другой - scheduleDateAndTime
.
Я создал DTO с отображением на модель student
и добавил свойство навигации в scheduleDateAndTime
Миграция
public partial class AnotherMigrationTwoTWOTwotwo : DbMigration
{
public override void Up()
{
DropForeignKey("dbo.Students", "scheduleDateAndTime_id", "dbo.ScheduleDateAndTimes");
DropIndex("dbo.Students", new[] { "scheduleDateAndTime_id" });
RenameColumn(table: "dbo.Students", name: "scheduleDateAndTime_id", newName: "scheduleDateAndTimeid");
AlterColumn("dbo.Students", "scheduleDateAndTimeid", c => c.Int(nullable: false));
CreateIndex("dbo.Students", "scheduleDateAndTimeid");
AddForeignKey("dbo.Students", "scheduleDateAndTimeid", "dbo.ScheduleDateAndTimes", "id", cascadeDelete: true);
}
public override void Down()
{
DropForeignKey("dbo.Students", "scheduleDateAndTimeid", "dbo.ScheduleDateAndTimes");
DropIndex("dbo.Students", new[] { "scheduleDateAndTimeid" });
AlterColumn("dbo.Students", "scheduleDateAndTimeid", c => c.Int());
RenameColumn(table: "dbo.Students", name: "scheduleDateAndTimeid", newName: "scheduleDateAndTime_id");
CreateIndex("dbo.Students", "scheduleDateAndTime_id");
AddForeignKey("dbo.Students", "scheduleDateAndTime_id", "dbo.ScheduleDateAndTimes", "id");
}
}
StudentDto
класс модели:
public class StudentDto
{
public int id { get; set; }
public string name { get; set; }
public byte age { get; set; }
public string subjectStudying { get; set; }
public string disability { get; set; }
public string additionalInformation { get; set; }
public ScheduleDateAndTimeDto ScheduleDateAndTime { get; set; }
public int scheduleDateAndTimeid { get; set; }
}