SQL enginie: MS SQL.
EF Core packages versions:
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
I've changed the existing column, which had index on it created few migrations earlier:
// ... other changes
migrationBuilder.CreateIndex(
name: "IX_Interactions_OrganisationToId",
table: "Interactions",
column: "OrganisationToId");
I've changed it from optional to required (not-nullable). Entity Framework Core generated such a migration:
// ... other changes
migrationBuilder.AlterColumn<Guid>(
name: "OrganisationToId",
table: "Interactions",
nullable: false);
But you cannot alter the column which has index on it. Unfortunately EF Core is not supporting this in case of changing field to non-nullable.
When renaming field - works like a charm and before rename simply drops index and restores it after alter.
Is there any way to configure EF Core that he'll cover this case and generate correct migration?
At the moment I've modified the migration and dropped down the index before altering the column, and manually restore it after the operation.
It did the job.
// drop index before altering column
migrationBuilder.DropIndex(name: "IX_Interactions_OrganisationToId", table: "Interactions");
// actually altering column
migrationBuilder.AlterColumn<Guid>(
name: "OrganisationToId",
table: "Interactions",
nullable: false);
// restore index
migrationBuilder.CreateIndex(
name: "IX_Interactions_OrganisationToId",
table: "Interactions",
column: "OrganisationToId");