Ao executar o comando update-database via Migrations do EF CodeFirst para atualizar um database hospedado no SQL Azure você pode receber uma mensagem de erro:
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

Pesquisando sobre o erro descobri que é um bug já reportado do EF 6 Alfa 3.
O motivo apresentado por Andrew Peters (EF Developer) foi:
This causes Migrations not to work on Azure because the history table needs at least one clustered PK
Como resolver:
1- Atualize a versão da biblioteca do EF 6 (a correção foi disponibilizada em 07/03/2013).
2 -Caso não seja possível a atualização da biblioteca, existe um workaround:
Crie uma classe de custom migration SQL generator
using System.Data.Entity.Migrations.Model;
using System.Data.Entity.Migrations.Sql;
public class AzureSqlGenerator : SqlServerMigrationSqlGenerator
{
protected override void Generate(CreateTableOperation createTableOperation)
{
if ((createTableOperation.PrimaryKey != null)
&& !createTableOperation.PrimaryKey.IsClustered)
{
createTableOperation.PrimaryKey.IsClustered = true;
}
base.Generate(createTableOperation);
}
}
E registre a sua custom generator no arquivo Configuration.cs da pasta Migrations
internal sealed class Configuration : DbMigrationsConfiguration<MyContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
// Esta linha abaixo:
SetSqlGenerator("System.Data.SqlClient", new AzureSqlGenerator());
}
protected override void Seed(MyContext context)
{
}
}
Pronto!
Pode rodar novamente o comando update-database que o problema estará resolvido.
Até a próxima 😉
