[英]Getting error when running update-database for MySql database: Table 'xxx' doesn't exist
I have recently changed some properties in my class (Notification) and as usual I added a migration for the changes. 最近,我在班级(通知)中更改了一些属性,并且像往常一样,为这些更改添加了迁移。 I ran the update-database command and got an error saying the table 'xxx.dbo.notifications' doesn't exist.
我运行了update-database命令,并收到一条错误消息,指出表'xxx.dbo.notifications'不存在。
The table is still there so why am I getting this error? 该表仍然存在,所以为什么会出现此错误?
Edit: the migration code 编辑:迁移代码
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);
}
Edit: I reverted the changes to before the error occurred. 编辑:我将更改还原到发生错误之前。 I added the ProductOptionId property to the model, added the migration, and updated the database successfully.
我将ProductOptionId属性添加到模型中,添加了迁移,并成功更新了数据库。
The problem seems to be happening when I'm changing the PaymentId property to null-able. 当我将PaymentId属性更改为可空值时,似乎发生了问题。
Does that make sense? 那有意义吗?
1- Make Sure That Table Is Created Into database after Your Migration 1-确保迁移后将表创建到数据库中
2- Make Sure That The Context Is Refereeing to The Same Database That You Have Migrated to 2-确保上下文引用您已迁移到的同一数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.