自引用实体可能会导致循环或多个级联路径

时间:2019-07-09 14:01:58

标签: c# entity-framework-core

我有以下实体:

Introducing FOREIGN KEY constraint 'FK_Departments_Departments_HeadDepartmentId' on table 'Departments' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.

我添加了迁移,然后尝试更新数据库,结果是:

builder.Entity<Department>()
                .HasOne(p => p.HeadDepartment)
                .WithMany(p => p.ChildDepartments)
                .HasForeignKey(p => p.HeadDepartmentId).OnDelete(DeleteBehavior.ClientSetNull);

我再试一次:

ServerManager

但这没有帮助。

0 个答案:

没有答案