In most cases, you can find a natural hierarchy to your objects. Sometimes there is some kind of "master" and all other objects have foreign key (FK) references to this master and to each other.
In this case, you can use an XML-like structure with each master object "containing" a lot of subsidiary objects. In this case, you insert the master first, and all the children have FK references to an existing object.
In some cases, however, there are relationships that can't be simple FK's to an existing object. In this case you have circular dependencies and you must (1) break this dependency temporarily and (2) recreate the dependency after the objects are loaded.
You do this by (a) defining your model to have an optional FK, (b) and having a temporary "natural key" reference. You'll load data without the proper FK (it's optional).
Then, after your data is loaded, you go back through a second pass and insert all of the missing FK references. Once this is done you can then modify your model to make the FK mandatory.
Program 1 - export from old database to simple flat-file. CSV format or JSON format or something simple.
for m in OldModel.objects.all():
aDict = { 'col1':m.col1, 'old_at_fk':m.fktoanothertable.id, 'old_id':id }
csvwriter.writerow( aDict )
Program 2 - read simple flat-file; build new database model objects.
# Pass 1 - raw load
for row in csv.reader:
new= NewModel.create( **row )
# Pass 2 - resolve FK's
for nm in NewModel.objects.all():
ref1= OtherModel.objects.get( old_id=nm.old_at_fk )
nm.properfk = ref1
nm.save()