I have a model that I would like to populate with csv data, I have followed a few tutorials on this and am now trying to do it on my own. This is the code that I have so far;
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project_name.settings')
import django
django.setup()
#Import models
from app_name.models import Instance
# Third Party Imports
import pandas as pd
# Pull csv data into script
file = 'path/to/file/filename.csv'
collected_data = pd.read_csv(file,index_col='Timestamp')
# this is a dataframe with three columns and a datetime index
for timestamp, row in collected_data.iterrows():
info1 = row[0]
info2 = row[1]
info3 = row[2]
inst = Instance.objects.get_or_create(timestamp = timestamp,
info1 = info1,
info2 = info2,
info3 = info3)[0]
I am getting the following error, which I don't really understand, as I am quite new to Django.
SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
Let me know if there is any more information needed for a MCVE