Fixing Drupal redirects to nonexistent nodes

Drupal 7I had strange situation crop up on a recent project: node teaser was coming up with a 404 page! I start looking into this issue and finally found that it was redirecting to a nonexistent node. When I ran the query below, I found that there were more then 5000 redirects to nonexistent nodes:

I decided to run an update to delete them:

This was just a one-time solution, but it is better then nothing! In the near future I will add a hook to prevent storing redirects to nonexistent nodes to begin with…

Keep on with the Drupal!