将EF迁移重置为清理平板 - 未生成唯一索引

问题描述 投票:0回答:1

我正在尝试根据本指南将迁移重置为干净的平板:

https://weblog.west-wind.com/posts/2016/Jan/13/Resetting-Entity-Framework-Migrations-to-a-clean-Slate

问题是一个DB表包含一个唯一索引,该索引是在其中一个迁移中添加的

CreateIndex("Localization_Resources", new string[] { "Culture", "Key" }, unique: true, name: "UX_Localization_Resources_Culture_Key"); 

根据指南运行add-migration Initial时,此索引不会重新生成干净的初始数据迁移。为什么这个索引没有生成初始迁移?怎么解决?谢谢。

entity-framework ef-migrations
1个回答
0
投票

如果它不是迁移的一部分,那么您必须使用流畅的API手动添加唯一索引,如下例所示。

modelBuilder.Entity<YourEntity>()
            .HasIndex(b => b.PropertyName)
            .IsUnique();
© www.soinside.com 2019 - 2024. All rights reserved.