entity-framework - 将 EF 迁移重置为全新状态 - 未生成唯一索引
问题描述
我正在尝试根据本指南将迁移重置为干净的状态:
问题是一个数据库表包含一个唯一索引,该索引是在其中一个迁移中添加的
CreateIndex("Localization_Resources", new string[] { "Culture", "Key" }, unique: true, name: "UX_Localization_Resources_Culture_Key");
add-migration Initial
并且当我按照指南运行时,该索引不会重新生成到干净的初始数据迁移中。为什么这个索引没有生成到初始迁移中?如何解决?谢谢你。
解决方案
如果它不是迁移的一部分,那么您必须使用 fluent API 手动添加唯一索引,如下例所示。
modelBuilder.Entity<YourEntity>()
.HasIndex(b => b.PropertyName)
.IsUnique();
推荐阅读
- python - 在做任何工作之前多处理退出
- c++ - 64位进程地址的读内存
- django - Django“您有 1 个未应用的迁移”,但应用了最后一次迁移
- spring-boot - Azure Iotedge 使用 --net=host 启动 docker,以便我可以访问我的 IP
- javascript - 如何生成/提供带有预渲染主体的 nuxt.js 应用程序
- active-directory - 启用 Windows 讲述人的组策略
- flutter - 在嵌套小部件中使用时,flutter I18n 引发异常
- selenium - 如何通过docker以非无头模式在linux中运行selenium java测试
- r - 为什么 names() 函数没有出现在 sys.calls() 输出堆栈中 - R
- python - 如何将位串拆分为任意位