I have a problem of creating a big amount of data with foreign keys in Django ORM on MySql. Let's say I have 2 models:
class Student(models.Model):
school = models.ForeignKey(School, related_name="students")
name = models.CharField(max_length=200, blank=True, default="")
class School(models.Model):
name = models.CharField(max_length=200, blank=True, default="")
Now I want to create a lot of schools that have a lot of students, and lets assume I already have a Data structure that have all the needed info for the creation of it.
The only way I found out so far is to create all the schools (in order to get the PK) and on the go to create a list of all the students(in all of the schools) and use bulk_create
to create the students.
It seems that there should be a better way to do this.
Because if for example we have 10K schools and 200 students in school the lowest I managed to do is ~10K inserts and that is to much.
Thank you in advance.