我最近在我的班级(通知)中更改了一些属性,并像往常一样为变更添加了迁移。 我运行了update-database命令并得到一个错误,说明表' xxx.dbo.notifications'不存在。
该表仍然存在,为什么我收到此错误?
编辑:迁移代码
public override void Up()
{
DropForeignKey("dbo.Notifications", "PaymentId", "dbo.Payments");
DropIndex("dbo.Notifications", new[] { "PaymentId" });
AddColumn("dbo.Notifications", "ProductOptionId", c => c.Int());
AlterColumn("dbo.Notifications", "PaymentId", c => c.Int());
CreateIndex("dbo.Notifications", "PaymentId");
CreateIndex("dbo.Notifications", "ProductOptionId");
AddForeignKey("dbo.Notifications", "ProductOptionId", "dbo.ProductOptions", "Id");
AddForeignKey("dbo.Notifications", "PaymentId", "dbo.Payments", "Id");
}
public override void Down()
{
DropForeignKey("dbo.Notifications", "PaymentId", "dbo.Payments");
DropForeignKey("dbo.Notifications", "ProductOptionId", "dbo.ProductOptions");
DropIndex("dbo.Notifications", new[] { "ProductOptionId" });
DropIndex("dbo.Notifications", new[] { "PaymentId" });
AlterColumn("dbo.Notifications", "PaymentId", c => c.Int(nullable: false));
DropColumn("dbo.Notifications", "ProductOptionId");
CreateIndex("dbo.Notifications", "PaymentId");
AddForeignKey("dbo.Notifications", "PaymentId", "dbo.Payments", "Id", cascadeDelete: true);
}
编辑:我在发生错误之前将更改还原为。我将ProductOptionId属性添加到模型中,添加了迁移,并成功更新了数据库。
当我将PaymentId属性更改为null时,问题似乎正在发生。
这有意义吗?
答案 0 :(得分:0)
1-确保在迁移后将表创建为数据库 2-确保上下文是对您已迁移到的同一数据库的裁判