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

编程入门 行业动态 更新时间:2024-10-24 06:26:23
本文介绍了无法在表上创建多个聚集索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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.

更多推荐

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

本文发布于:2023-10-25 08:56:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526498.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   表上   索引

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!