Sunday, 27 September 2015

Entity Framework: how to solve “FOREIGN KEY constraint may cause cycles or multiple cascade paths”?

Introducing FOREIGN KEY constraint 'FK_dbo.ChildProfile_dbo.SourceType_SourceTypeId' on table 'ChildProfile' 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.



Answer

Also you can modify your migration class. In my case in the migration class was:


Make  "cascadeDelete: false" Update-Database works perfectly.


OR
Add this code in context



protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }

Update-Database works perfectly.

2 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    .Net Online Course

    ReplyDelete
  2. Thankyou your post is very useful...

    ReplyDelete