Autodetect ForeignKeys and add dependencies/split on circulars