How to drop unique index with entity framework code first migrations

前端 未结 2 690
暗喜
暗喜 2021-01-21 07:22

I\'m using Entity Framework 5.0 with Code First migrations enabled.

I\'ve added Unique key by using:

CreateIndex(\"dbo.Groups\", \"Name\", true);
         


        
相关标签:
2条回答
  • 2021-01-21 07:35

    Ok, I solved this on my own :)

    Apparently I misused syntax for DropIndex. I assumed it takes name of column, but instead it takes name of index. This worked:

    DropIndex("dbo.Groups", "IX_Name");
    

    :)

    Talking to myself 2013!

    0 讨论(0)
  • 2021-01-21 07:48

    There is another answer to this:

    DropIndex("dbo.Groups", new[]{"Name"});
    

    There is an overload of DropIndex that takes column names, but it takes an array of them. So for a single column name you still have to wrap it in an array to get to the overload.

    0 讨论(0)
提交回复
热议问题