gpt4 book ai didi

sql - SQL Azure 中的 Code First 迁移 - 不支持没有聚集索引的表

转载 作者:行者123 更新时间:2023-12-04 18:45:20 25 4
gpt4 key购买 nike

我似乎无法通过代码优先迁移来创建 SQL Azure 数据库。

它一直提示 SQL Azure 缺乏对没有聚集索引的表的支持,而且我找不到创建数据库的方法。

注意: 我使用 CreateDatabaseIfNotExists 在第一次创建数据库时创建更改跟踪表,因为显然 DropCreateDatabaseIfModelChanges doesn't do that for you

    public partial class IUnityDbContext : DbContext
{
public IUnityDbContext()
: base("Name=IUnityDbContext")
{
Database.SetInitializer(new CreateDatabaseIfNotExists<IUnityDbContext>());
//Database.SetInitializer(new DropCreateDatabaseIfModelChanges<IUnityDbContext>());
}

public DbSet<User> Users { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new UserMap());

base.OnModelCreating(modelBuilder);
}
}




public partial class Initial : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Users",
c => new {
...
}
).PrimaryKey(u => u.UserId, clustered: true);
}

public override void Down()
{
DropTable("dbo.Users");
}
}

如果我尝试“更新数据库”,我会得到

 Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

数据库未创建。

更新:我从头开始并遵循 this guide启用自动迁移(划伤数据库并从不存在的数据库开始,这样我就不必从初始迁移中删除向上/向下代码)

这次我的数据库已成功创建(之前没有做到这一点),但表未创建,我仍然收到与以前相同的错误,即不支持没有聚集索引的表。

请指教

最佳答案

事实证明这是 Entity Framework 6 -Alpha 3 中的一个错误。我想我应该提到这一点。

https://stackoverflow.com/a/15282861/1267778

关于sql - SQL Azure 中的 Code First 迁移 - 不支持没有聚集索引的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15354953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com