Emma has already said how it's normally done and I'll +20 that.
So from what you've described you are manipulating the database directly to get a 1.9.x to a 3.4.highest - is that right?
You've ID'd a couple of problems and asking how you can resolve those. Don't have an answer for you there. But do have something of which you need to be aware and just haven't discovered it ... yet (or maybe you have ... dunno).
Massive changes in the way moodle handles files .. files associated with any course and uploaded by teacher/students in courses. Relates to the structure of moodledata.
Briefly, in 1.9, moodledata had course ID directories ... course ID 1 was front page and any files/backups/etc. related to the front page, one could find files in moodledata/1/
Those who migrated a 1.9.x site to a version 2, soon discovered the massive change ... courses no longer had a course ID directory in moodledata - rather, *all files* in any course were moved to the new structure .. moodledata/filedir/xx/xx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx and massive changes to mdl_files table as well. All of those files and all courses had a setting for 'legacy' files in mdl_files table.
So in the 3.4 that you are working on, check out the moodledata directory ... does it still have course id directories? Is there a 'filedir' directory? What's in 'filedir' if it exist?
In a migrated site, course ID directories existed ... but inspecting those one couldn't find files any more but a modinfo and inside there ### directories ... and inside those ###(#) ... they were certificates that students were awarded for completion of courses.
Never did figure out how to get those certs into the new file system and entries in DB as well.
You are, of course, welcome to pursue what you are doing but since 1.9.x -> migrations are coming fewer in number now ... if at all ... fewer folks will be attempting the feat now. Not bragging, but did have a lot of experience at migrating sites from 1.9.x to 2.2.highest, but using git ... not direct database manipulation. What things I learned, I've forgotten! :\
'spirit of sharing', Ken