在输入update-database之后,我遇到了以下错误:
无法在表'dbo.AppUsers'上创建多个聚集索引。在创建其他聚集索引之前,请删除现有的聚集索引'PK_dbo.AppUsers'。
我正在使用Azure移动服务。
我有三个数据模型:
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; }
}
涉及迁移,因为:
- 初始创建在_MigrationHistory表中,但不在解决方案资源管理器中的迁移文件夹中。
- 当我添加迁移AddAll时,没有任何错误,并且AddAll出现在迁移文件夹中,但不在表中。
在上下文文件中:
public class ICbackendContext : DbContext
{
public DbSet<AppUser> AppUsers { get; set; }
public DbSet<PlaceItem> PlaceItems { get; set; }
public DbSet<RatingItem> RatingItems { get; set; }
}
DbContext
配置类的protected override void OnModelCreating(DbModelBuilder modelBuilder)
方法中添加以下代码:modelBuilder.Conventions.Add(new AttributeToColumnAnnotationConvention<TableColumnAttribute, string>("ServiceTableColumn", (property, attributes) => attributes.Single().ColumnType.ToString()));
。这将生成正确的迁移代码。我已经验证过了。 - gorillapower