fix: 稳定字典种子外键生成

This commit is contained in:
2025-12-02 12:56:23 +08:00
parent 331edbb44a
commit 2043e227d7

View File

@@ -318,6 +318,12 @@ public sealed class AppDataSeeder(
long tenantId, long tenantId,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
// 确保分组已持久化以获取正确的主键,避免 FK 约束报错。
if (!dbContext.Entry(group).IsKeySet || group.Id == 0)
{
await dbContext.SaveChangesAsync(cancellationToken);
}
var materializedItems = seedItems var materializedItems = seedItems
.Where(item => !string.IsNullOrWhiteSpace(item.Key) && !string.IsNullOrWhiteSpace(item.Value)) .Where(item => !string.IsNullOrWhiteSpace(item.Key) && !string.IsNullOrWhiteSpace(item.Value))
.ToList(); .ToList();