How to drop unique index with entity framework cod

2019-02-24 14:37发布

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

I've added Unique key by using:

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

Now I want to remove existing Unique key with next migration's Down() method by using:

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

However I get the message:

Cannot drop the index 'dbo.Groups.Name', because it does not exist or you do not have permission.

I'm using connection string that assumes I'm DBO. What else could be wrong?

2条回答
2楼-- · 2019-02-24 15:22

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.

查看更多
Summer. ? 凉城
3楼-- · 2019-02-24 15:37

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!

查看更多
登录 后发表回答