Postgresql Add Constraint Foreign Key If Conditional In Python