Fixes #5551 removes corrupt entities from database