Always work with SQLAlchemy objects instead of id columns. Error checking and cascades only work if you work with SQLAlchemy objects. In this case, you need `EventRedirect.query.filter_by(name=old_name, profile=profile).first()`.