Code First Migrations in SQL Azure - Tables without a clustered index are not supported

我怕爱的太早我们不能终老 提交于 2019-12-05 00:10:13

问题


I can't seem to get my Code-First Migration to create my SQL Azure database.

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.

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.

The database is not created.

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.

Please advise


回答1:


Turns out to be a bug in Entity Framework 6 -Alpha 3. I guess I should've mentioned that.

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




回答2:


This one looks similar (although it's not the ideal solution imho): Entity Framework Many-to-Many Clustered vs. Nonclustered Index



来源:https://stackoverflow.com/questions/15354953/code-first-migrations-in-sql-azure-tables-without-a-clustered-index-are-not-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!