【发布时间】:2013-02-27 14:17:48
【问题描述】:
我似乎无法通过代码优先迁移来创建我的 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");
}
}
如果我尝试 `Update-Database 我会得到 p>
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
数据库未创建。
更新:我从头开始并按照this guide 启用自动迁移(刮掉数据库并从不存在的数据库开始,因此我不必删除向上/向下代码从初始迁移)
这次我的数据库已成功创建(之前没有做到这一点),但没有创建表,我仍然得到与以前相同的错误,即不支持没有聚集索引的表。
请指教
【问题讨论】:
-
所有代码看起来都正确,为什么没有人回答?
标签: sql entity-framework azure ef-code-first azure-sql-database