如何使用实体框架代码首次迁移删除唯一索引 [英] How to drop unique index with entity framework code first migrations

查看:162
本文介绍了如何使用实体框架代码首次迁移删除唯一索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆