Fixed things in foreign key handling