Hi @Jake Ford ,
As you discussed, the issue relates the cascade delete behaviors.
Some databases, most notably SQL Server, have limitations on the cascade behaviors that form cycles. When you update/delete the related entities, it might case the following exception:
Microsoft.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint ' {Foreign Key}' on table '{Foreign table}' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
There are two ways to handle this situation:
- Change one or more of the relationships to not cascade delete.
- Configure the database without one or more of these cascade deletes, then ensure all dependent entities are loaded so that EF Core can perform the cascading behavior.
So, you can set the foreign key as nullable or configure cascading behaviors (such as set it as NoAction). More detailed information, see Database cascade limitations.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion