如何使用实体框架代码首次迁移删除唯一索引 [英] How to drop unique index with entity framework code first migrations
问题描述
我已经使用Entity Framework 5.0启用了代码优先迁移。
I'm using Entity Framework 5.0 with Code First migrations enabled.
$ b
CreateIndex("dbo.Groups", "Name", true);
现在我想使用下一个迁移的Down()方法删除现有的唯一键:
Now I want to remove existing Unique key with next migration's Down() method by using:
DropIndex("dbo.Groups", "Name");
但是我收到消息:
无法删除索引'dbo.Groups.Name',因为它不存在或您没有权限。
Cannot drop the index 'dbo.Groups.Name', because it does not exist or you do not have permission.
我使用的连接字符串假设我是DBO。还有什么可能是错的?
I'm using connection string that assumes I'm DBO. What else could be wrong?
推荐答案
还有另一个答案:
DropIndex("dbo.Groups", new[]{"Name"});
有是DropIndex的重载,它使用列名,但需要他们的阵列。因此,对于单个列名称,您仍然必须将其包装到数组中以获得重载。
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.
这篇关于如何使用实体框架代码首次迁移删除唯一索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!