code首先迁移在SQL Azure中 - 表没有一个聚集索引不支持 [英] Code First Migrations in SQL Azure - Tables without a clustered index are not supported
问题描述
我似乎无法让我的code-首先迁移创建我的SQL Azure数据库。
I can't seem to get my Code-First Migration to create my SQL Azure database.
它使抱怨SQL Azure中缺乏对表支持,而聚集索引,我不能找到周围一个方法来创建我的数据库。
It keeps complaining about SQL Azure's lack of support for tables without clustered indexes and I cant find a way around to create my database.
注意:我用 CreateDatabaseIfNotExists
以创建的变化对第一次创建数据库跟踪表,因为显然 DropCreateDatabaseIfModelChanges
为您没有做到这一点。
Note: I'm using CreateDatabaseIfNotExists
to create the change tracking tables on the first time database creation because apparently 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");
}
}
如果我尝试'更新数据库内我得到
If I try to `Update-Database I get
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
不创建数据库。
更新:我从头开始,随后<一个href=\"http://geekswithblogs.net/michelotti/archive/2012/11/13/enable-automatic-$c$c-first-migrations-on-sql-database-in-azure.aspx\"相对=nofollow>本指南启用自动迁移(划伤数据库,并开始与一个不存在的之一,所以我没有从初始迁移删除向上/向下code)
UPDATE: I started from scratch and followed this guide to enable Automatic Migrations (scratched the database and started with a non-existing one so I didn't have to remove the Up/Down code from the Initial migration)
我的成功创建数据库这个时候(没得到这个前远),但表不创建,我仍然得到同样的错误作为前约没有没有聚簇索引对表的支持。
This time my database was successfully created (Did not get this far before) but the tables are not created and I still get the same error as before about no support for tables without clustered indexes.
请指教
推荐答案
原来是在实体框架6-α3.我想我应该提到的错误。
Turns out to be a bug in Entity Framework 6 -Alpha 3. I guess I should've mentioned that.
<一个href=\"http://stackoverflow.com/a/15282861/1267778\">http://stackoverflow.com/a/15282861/1267778
这篇关于code首先迁移在SQL Azure中 - 表没有一个聚集索引不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!