Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop unique index with entity framework code first migrations

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?

like image 391
Admir Tuzović Avatar asked Dec 06 '22 07:12

Admir Tuzović


1 Answers

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.

like image 111
Josh Gallagher Avatar answered Jan 07 '23 01:01

Josh Gallagher