Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts

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.