Switch SQLAlchemy FOREIGN KEY / UNIQUE code to LBYL

SQLAlchemy’s exceptions provide less-than-stellar detail about precisely
what error occurred.  Discussion on <irc://irc.freenode.net/sqlalchemy>
suggests that using an EAFP style with SQLAlchemy is in fact the wrong
way to go – the database FOREIGN KEY constraints and the corresponding
exceptions should be a ‘last line of defence’.  I’ve thus switched code
that deals with FOREIGN KEY and UNIQUE constraints to LBYL-style.