I am getting this error when generate Database from Entity Framework Code First.
I didn′t see any problem with script:
alter table [dbo].[Votes] add constraint [Post_Votes] foreign key ([Post_Id]) references [dbo].[Posts]([Id]) on delete cascade;
alter table [dbo].[Votes] add constraint [User_Votes] foreign key ([Voter_Id]) references [dbo].[Users]([Id]) on delete cascade;
Each reference is to different tables!
I can have just one on delete cascade per table?
Edit: I think I found the problem, the bug is EF:
If I have 3 tables: Users, Posts and Votes.
And the relations:
Post.AuthorId -> User.Id
Votes.PostId -> Post.Id
Votes.UserId -> User.Id
Sql correctly generate a error, because if I delete a post, I will have 2 path to Votes: User -> Vote and User -> Post -> Vote
But entity framework dont detect this and generate the 3 foreign key with on delete cascade.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…