Improved plugin manager to better handle foreign key constraints.