Django 2.0 Populating Database with a Script
问题 I'm trying to populate my Django database with a script so I don't have to enter in the data manually. So far I have the following: from my_app.models import ModelInApp import django django.setup() def add_data(data1, data2): d, created = ModelInApp.objects.get_or_create(data1=data1, data2=data2) print("- Data: {0}, Created: {1}".format(str(d), str(created))) return d def populate(): # data is a list of lists for row in data: data1 = row[0] data2 = row[1] add_data(data1, data2) if __name__ ==