【发布时间】:2017-01-31 16:47:14
【问题描述】:
我的后端是在 .NET 中构建的,通过在解决方案中包含一个表,我收到以下错误:
无法在表 'dbo.Favorit' 上创建多个聚集索引。 在创建之前删除现有的聚集索引 'PK_dbo.Favorit' 另一个。
此代码是在Add-Migration CreateFavorit 和update-database 命令之后生成的:
namespace appService.Migrations
{
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.Migrations;
public partial class CreateFavorit : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Favorit",
c => new
{
Id = c.String(nullable: false, maxLength: 128,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Id")
},
}),
Nome = c.String(),
Lat_dest = c.Double(nullable: false),
Lon_dest = c.Double(nullable: false),
Id_usuario = c.String(),
Endereco = c.String(),
MeioTransporte = c.String(),
Id_usuario_2 = c.String(),
Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion",
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Version")
},
}),
CreatedAt = c.DateTimeOffset(nullable: false, precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "CreatedAt")
},
}),
UpdatedAt = c.DateTimeOffset(precision: 7,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "UpdatedAt")
},
}),
Deleted = c.Boolean(nullable: false,
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Deleted")
},
}),
})
.PrimaryKey(t => t.Id)
.Index(t => t.CreatedAt, clustered: true);
}
public override void Down()
{
DropIndex("dbo.Favorit", new[] { "CreatedAt" });
DropTable("dbo.Favorit",
removedColumnAnnotations: new Dictionary<string, IDictionary<string, object>>
{
{
"CreatedAt",
new Dictionary<string, object>
{
{ "ServiceTableColumn", "CreatedAt" },
}
},
{
"Deleted",
new Dictionary<string, object>
{
{ "ServiceTableColumn", "Deleted" },
}
},
{
"Id",
new Dictionary<string, object>
{
{ "ServiceTableColumn", "Id" },
}
},
{
"UpdatedAt",
new Dictionary<string, object>
{
{ "ServiceTableColumn", "UpdatedAt" },
}
},
{
"Version",
new Dictionary<string, object>
{
{ "ServiceTableColumn", "Version" },
}
},
});
}
}
}
服务器 microsoft-azure,数据库 SQLServer。 如何解决这个问题?或者,这个错误是什么? 谢谢。
编辑:
模型类:
namespace appService.DataObjects
{
public class Favorit : EntityData
{
public string Nome { get; set; }
public double Lat_dest { get; set; }
public double Lon_dest { get; set; }
public string Id_usuario { get; set; }
public string Endereco { get; set; }
public string MeioTransporte { get; set; }
public string Id_usuario_2 { get; set; }
}
}
【问题讨论】:
-
嗯,错误表明您在表中只能有一个聚集索引。我认为它正在为
Id创建一个,因为它是主键,然后为CreatedAt创建另一个,正如迁移中定义的那样。我不确定它为什么要创建它。你能分享你的模型课吗? -
@juunas 当然,我可以分享。
-
@juunas 在那里
标签: c# .net azure azure-mobile-services backend