简体   繁体   English

为MySql数据库运行更新数据库时出错:表'xxx'不存在

[英]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.

相关问题 MySql上的EF Core`update-database`失败,`__EFMigrationsHistory'不存在。 - EF Core `update-database` on MySql fails with `__EFMigrationsHistory' doesn't exist` 运行更新数据库 EFCore 时出现算术溢出错误 - Arithmetic Overflow Error When running Update-Database EFCore 运行更新数据库实体框架时出错2 - Error running update-database entityframeworkcore 2 在MVC5中运行Update-Database时出错 - Error while running Update-Database in MVC5 命令更新数据库-Context“ IdentityDbContext”不会创建表 - Command Update-Database -Context “IdentityDbContext” Doesn't Create Tables 运行代码第一次迁移update-database时出错 - Error running code first migration update-database 使用Entity Framework,Code First(POCO)和Code Contracts运行Update-Database时出错 - Error When running Update-Database using Entity Framework, Code First (POCO) and Code Contracts 使用更新数据库命令MVC 4时出错 - Error when using Update-Database command MVC 4 MySQL更新数据库System.FormatException - Mysql update-database System.FormatException 尝试首先更新数据库代码时出错 - Error on trying to Update-Database code first
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM