无法在表上创建多个聚集索引

Cannot create more than one clustered index on table(无法在表上创建多个聚集索引)
本文介绍了无法在表上创建多个聚集索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am having the following error after typing update-database:

Cannot create more than one clustered index on table 'dbo.AppUsers'. Drop the existing clustered index 'PK_dbo.AppUsers' before creating another.

I am working on an Azure mobile service.

I have three data models:

public class AppUser : EntityData
{
    public string Username { get; set; }
    public virtual ICollection<RatingItem> userRatings { get; set; }
}

public class PlaceItem : EntityData
{
    public string PlaceName { get; set; }
    public int Group { get; set; }
    public string XCoordinate { get; set; }
    public string YCoordinate { get; set; }
}

public class RatingItem : EntityData
{
    public int Ratings { get; set; }
    public string PlaceId { get; set; }
    public AppUser user { get; set; }
}

It has to do with migration because :

  • The initial create is in the _MigrationHistory table, but isn't in the migration folder in the solution explorer.
  • When I add-migration AddAll, I don't get any errors, and AddAll appears in the migration folder, but not in the table.

In the context file:

public class ICbackendContext : DbContext
{
        public DbSet<AppUser> AppUsers { get; set; }
        public DbSet<PlaceItem> PlaceItems { get; set; }
        public DbSet<RatingItem> RatingItems { get; set; }

}

解决方案

Generally, this error message is caused by not running the Mobile Apps/Mobile Services DB generator. Entity Framework does not have an annotation for creating a clustered index that is not a primary key, so the mobile server SDK manually creates the right SQL statements to set CreatedAt as a non-primary key clustered index.

To resolve this, run the database generator before migrations are applied. In the MigrationsConfiguration.cs file, include the following:

public Configuration()
{
   AutomaticMigrationsEnabled = false;
   SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
}

To learn more, see How to make data model changes to a .NET backend mobile service. The topic applies to both Mobile Services and Mobile Apps, though some namespaces are different in Mobile Apps.

这篇关于无法在表上创建多个聚集索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)