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.
这篇关于无法在表上创建多个聚集索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在表上创建多个聚集索引
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01