Fix crash when adding foreign keys to a new table. (issue #344)