How to drop unique index with entity framework code first migrations

泪湿孤枕 提交于 2019-12-02 00:12:35

问题


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?


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/16862208/how-to-drop-unique-index-with-entity-framework-code-first-migrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!