Add a unique constraint and foreign keys