fix: 稳定字典种子外键生成
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user