SQL Azure中的代码优先迁移 - 不支持具有聚簇索引的表 [英] Code First Migrations in SQL Azure - Tables without a clustered index are not supported

查看:108
本文介绍了SQL Azure中的代码优先迁移 - 不支持具有聚簇索引的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法获得我的代码优先迁移来创建我的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.

数据库未创建。

更新:我从头开始,按照本指南启用自动迁移(划伤数据库并以不存在的方式启动,所以我不必删除Up /初始迁移中的代码)

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.

请指教

推荐答案

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

这篇关于SQL Azure中的代码优先迁移 - 不支持具有聚簇索引的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆