Introducing FOREIGN KEY constraint 'xxx' on table 'xxx 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. See previous errors.


Merhaba;

"Introducing FOREIGN KEY constraint 'xxx' on table 'xxx 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. See previous errors."

EF code Firt update-database dediğimizde aldığımız bu hatanın çözümü için oluşturulan migration dosyamızı açıp içerisnde bulunan ilgili tabloların kodlarındaki ForeignKey in cascadeDelete  özelliğini false yapmamız gerekmektedir.

Örnek:
 ".ForeignKey("dbo.AspNetUsers", t => t.UpdateUserId, cascadeDelete: false)"

yada ;

ModelContext dosyanıza  aşağıdaki gibi WillCascadeOnDelete özelliğini false yapabilirsiniz ;

        modelBuilder.Entity<AspNetUser>()
             .HasMany(e => e.TAble)
             .WithRequired(e => e.AspNetUser)
             .HasForeignKey(e => e.UserId)
               .WillCascadeOnDelete(false);





İyi çalışmalar

Yorumlar

Bu blogdaki popüler yayınlar

An error occurred while updating the entries. See the inner exception for details.

Unable to load the specified metadata resource.