Error deploying to SQL Azure using EF 6 alpha3 Code First and Migrations creating __MigrationHistory table

First, I use EF 6 alpha 3. When I try to create an Azure SQL database running the Update-Database command, I get the following error:

Tables without a clustered index are not supported in this version of SQL Server. Create a clustered index and try again.

I found an error in the sql command to create the __MigrationHistory table.

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])
)

Does anyone know how I can solve this problem?

Thank,

+3
source share
1 answer

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

There is a fairly simple way:

1) Create your own SQL migration 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) :

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

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

    protected override void Seed(MyContext context)
    {
    }
}
+13

All Articles