带有 .NET 后端的 Azure 移动服务 - 数据库中已经有一个名为的对象

Azure mobile services with .NET backend- There is already an object named in the database

我已经按照 Microsoft 的教程使用 Azure 门户为 Xamarin iOS 应用程序创建了一个 .NET 后端:tutorial

然后我使用一个现有的数据库和这个新的后端。但是,当我尝试登录我的移动应用程序时,登录失败并出现上述错误:

There is already an object named in the database

现有数据库在不同的订阅下,将被停用。我将它导入到新订阅中并进行了设置。

我在这里看到了很多类似的问题,也尝试了一些解决方案。我仍然有错误。

自从我更改了新后端中的命名空间后,我从 Whosebug 上的一个答案中读到了这个:

There is a table in your data base called dbo.__MigrationHistory. The table has a column called ContextKey. The value of this column is based on your namespace. for example is "DataAccess.Migrations.Configuration". When you change the namespace, it causes duplicate table names with different namespaces. So, after you change namespace in code side, change the namespace in this table in database, too, (for all rows).

我怀疑这可能是我的问题,但我目前无法访问我的数据库。

我也试过这个解决方案,但没有用:

Database.SetInitializer<YourContext>(null);

最后,我尝试在 Xamarin Studio 的包控制台扩展中使用 update-database 命令,但出现错误 :

command update-databse not found

我现在不确定如何解决这个问题。有人能给我指出正确的方向吗?

谢谢。

编辑

根据上面关于更改上下文的解释,我已经在 Configuration.cs class 中更新了它,如下所示:

internal sealed class Configuration : DbMigrationsConfiguration<testService.Models.testserviceContext>  // new namespace changed here
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
        AutomaticMigrationDataLossAllowed = true;

        SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
    }

  }

这会更新 dbo.__MigrationHistory table 还是我还需要 运行 更新命令?

我设法通过更改 dbo.__MigrationHistory table 中所有行的 contextKey 值解决了这个问题,根据上面的解释 Elnaz SO question。我正在查看指向 DBContext 的错误名称空间。所以不是这个:

testService.Models.testserviceContext 

来自这一行:

internal sealed class Configuration : DbMigrationsConfiguration<testService.Models.testserviceContext>  // new namespace changed here

我将 table 中的值更新为:

testService.Migrations.Configuration

这是我配置的新命名空间 class。

这解决了问题,我现在可以登录我的数据库了。