iT邦幫忙

0

[筆記系列]MySql EF6,Code-first,修改有值欄位Update-Database,error:Table '專案.dbo.資料表' doesn't exist

遇到這個問題
說實在卡了很久
想說用Mssql都沒問題
第一次寫專案EF用MySql
以下是修改欄位後產出的 Migrations

    public override void Up()
    {
        DropPrimaryKey("dbo.Error_msg");
        AlterColumn("dbo.Error_msg", "LangId", c => c.Int(nullable: false));
        AddPrimaryKey("dbo.Error_msg", new[] { "ErrorCode", "LangId" });
        DropColumn("dbo.Error_msg", "LandId");
    }
    
    public override void Down()
    {
        AddColumn("dbo.Error_msg", "LandId", c => c.Int(nullable: false));
        DropPrimaryKey("dbo.Error_msg");
        AlterColumn("dbo.Error_msg", "LangId", c => c.Int());
        AddPrimaryKey("dbo.Error_msg", new[] { "ErrorCode", "LandId" });
    }
    

一旦update-database時就會出現 Table '專案.dbo.Error_msg' doesn't exist

但我把dbo.槓掉,就能work!

    public override void Up()
    {
        DropPrimaryKey("Error_msg");
        AlterColumn("Error_msg", "LangId", c => c.Int(nullable: false));
        AddPrimaryKey("Error_msg", new[] { "ErrorCode", "LangId" });
        DropColumn("Error_msg", "LandId");
    }
    
    public override void Down()
    {
        AddColumn("Error_msg", "LandId", c => c.Int(nullable: false));
        DropPrimaryKey("Error_msg");
        AlterColumn("Error_msg", "LangId", c => c.Int());
        AddPrimaryKey("Error_msg", new[] { "ErrorCode", "LandId" });
    }
    

以上記錄一下


尚未有邦友留言

立即登入留言