Fixed bug where foreign keys would not be added if a primary was set