mysql - Django bulk_create of large datasets with foreign keys -


i have problem of creating big amount of data foreign keys in django orm on mysql. let's 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 want create lot of schools have lot of students, , lets assume have data structure have needed info creation of it.

the way found out far create schools (in order pk) , on go create list of students(in of schools) , use bulk_create create students.

it seems there should better way this.

because if example have 10k schools , 200 students in school lowest managed ~10k inserts , much.

thank in advance.

i think doing incorrectly. better use fixtures this

read more https://docs.djangoproject.com/en/1.10/howto/initial-data/ , https://code.djangoproject.com/wiki/fixtures

basically create file store current data of db , run command ./manage.py loaddata handle upload in optimal way


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -