【发布时间】:2017-09-08 09:55:20
【问题描述】:
我最近更改了班级(通知)中的一些属性,并且像往常一样添加了更改的迁移。 我运行了 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 属性更改为可空时,问题似乎正在发生。
这有意义吗?
【问题讨论】:
-
这看起来不像 MySQL,这似乎是 ms sql server。
-
@Shadow 是什么让你这么认为?
-
xxx.dbo.notifications- 在 MySQL 中,您可以有xxx.notifications表或xxx.dbo表,但路径中不能有 3 个元素。表只与数据库关联(模式)。 -
我可以向你保证,它是 MySQL。我在它的迁移配置 cos 中有以下行: SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());这是我第一次遇到这个问题
-
你的数据库可能是MySQL,但是报错信息中的表名不能存在于MySQL中。期间。
标签: c# mysql ef-code-first