3

最初にEF6alpha3コードを使用しています。Update-Databaseコマンドを実行してSQLAzureでデータベースを作成しようとすると、次のエラーが発生します。

クラスタ化インデックスのないテーブルは、このバージョンのSQLServerではサポートされていません。クラスタ化されたインデックスを作成して、再試行してください。

エラーを__MigrationHistoryテーブル作成SQLコマンドまで追跡しました。

CREATE TABLE [dbo].[__MigrationHistory] (
    [MigrationId] [nvarchar](255) NOT NULL,
    [ContextKey] [nvarchar](512) NOT NULL,
    [Model] [varbinary](max) NOT NULL,
    [ProductVersion] [nvarchar](32) NOT NULL,
    CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY NONCLUSTERED ([MigrationId], [ContextKey])
)

誰かがこの問題を回避する方法について何か考えがありますか?

ありがとう、

4

1 に答える 1

13

This is a bug in Alpha 3 - Sorry for the inconvenience.

There is a pretty easy workaround:

1) Create a custom migration SQL generator:

public class AzureSqlGenerator : SqlServerMigrationSqlGenerator
{
    protected override void Generate(CreateTableOperation createTableOperation)
    {
        if ((createTableOperation.PrimaryKey != null)
            && !createTableOperation.PrimaryKey.IsClustered)
        {
            createTableOperation.PrimaryKey.IsClustered = true;
        }

        base.Generate(createTableOperation);
    }
}

2) Register the custom generator in your migrations configuration:

internal sealed class Configuration : DbMigrationsConfiguration<MyContext> 
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;

        SetSqlGenerator("System.Data.SqlClient", new AzureSqlGenerator());
    }

    protected override void Seed(MyContext context)
    {
    }
}
于 2013-03-07T22:17:53.383 に答える