I spent quite some time to figure this out. I am just trying to import a CSV file using Python csv module and Django get_or_create ().
This is my simple code (built on this code):
import csv from .models import Person def import_data(): with open('/path/to/csv/people_list.csv') as f: reader = csv.reader(f) for row in reader: _, created = Org.objects.get_or_create( name=row[0], p_id=row[1], current_status=row[2], )
I get the following error when import_data () is run in the shell
peoplelisting.models.DoesNotExist: Person matching query does not exist.
Yes, this particular Person does not exist, but is the purpose of using get_or_create () really? If it does not exist, create it?
python django csv
Anupam Mar 30 '17 at 10:07 on 2017-03-30 10:07
source share