Foreign key constraint may cause cycles or multiple cascade paths?

后端 未结 9 1285
感情败类
感情败类 2020-11-21 23:07

I have a problem when I try to add constraints to my tables. I get the error:

Introducing FOREIGN KEY constraint \'FK74988DB24B3C886\' on table \'Empl

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 23:54

    My solution to this problem encountered using ASP.NET Core 2.0 and EF Core 2.0 was to perform the following in order:

    1. Run update-database command in Package Management Console (PMC) to create the database (this results in the "Introducing FOREIGN KEY constraint ... may cause cycles or multiple cascade paths." error)

    2. Run script-migration -Idempotent command in PMC to create a script that can be run regardless of the existing tables/constraints

    3. Take the resulting script and find ON DELETE CASCADE and replace with ON DELETE NO ACTION

    4. Execute the modified SQL against the database

    Now, your migrations should be up-to-date and the cascading deletes should not occur.

    Too bad I was not able to find any way to do this in Entity Framework Core 2.0.

    Good luck!

提交回复
热议问题