Troubleshoot dead references in DB

Hi. We noticed dead references in our app DB: some rows in the reference table refer to non-existent objects. To find the culprit I want to create a foreign key on the database level. Is this a good idea? Does Mendix always insert/delete objects and references in proper order?
1 answers

Maybe an issue with incorrectly setup dlete behavior in the domain model?

Or if you are deleting the data with the help of microflows this might cause an issue.

Issues can also arise when deleting data without using the delete behavior from java actions.

References are normally inserted and deleted in proper order, but when delete behavior is not set or implemented the referenced object might be deleted without the delete of the parent object e.g.

Another issue might be that the refrenced object is not saved when creating this object, then the object seems to be available while adding the data, but later on you will see that this record is not persisted in the db. 

Another issue might be a modeling error where you have autocommited objects being created and automatically deleted by the platform as these are not explicitly saved.