The DELETE statement conflicted with the REFERENCE constraint in ASP.NET Dynamic Data The DELETE statement conflicted with the REFERENCE constraint in ASP.NET Dynamic Data asp.net asp.net

The DELETE statement conflicted with the REFERENCE constraint in ASP.NET Dynamic Data


You can implement a cascading delete for Application_User_Access table. For this you need to modify your DB schema a little bit. Concretely remove the previous reference from the Application_User_Access to the Application_User table and add a new one:

--not sure about the column names thoughALTER TABLE Application_User_AccessADD CONSTRAINT FK_Application_User_Access_Application_UserFOREIGN KEY (used_id)REFERENCES Application_User(id)ON DELETE CASCADEGO

Notice that ON DELETE CASCADE thing. It means that whenever the primary key record is deleted the foreign key record referencing it will be removed as well.