Я новичок в Django, и я не вижу никакого «простого» способа сделать то, что я хочу.
У меня есть свежее приложение django, и я создал начальную миграцию своей базы данных.У него есть один стол.Все кажется хорошим, и я создал скрипт на python для импорта данных.Я сразу же получаю сообщение об ошибке ниже после его запуска:
django.core.exceptions.ImproperlyConfigured: Запрошенная настройка INSTALLED_APPS, но настройки не настроены.Вы должны либо определить переменную окружения DJANGO_SETTINGS_MODULE, либо вызвать settings.configure () перед доступом к настройкам.
Модель
from django.db import models
class Person(models.Model):
playerID = models.TextField()
birthYear = models.IntegerField()
birthMonth = models.IntegerField()
birthDay = models.IntegerField()
birthCountry = models.TextField()
birthState = models.TextField()
birthCity = models.TextField()
deathYear = models.IntegerField()
deathMonth = models.IntegerField()
deathDay = models.IntegerField()
deathCountry = models.TextField()
deathState = models.TextField()
deathCity = models.TextField()
nameFirst = models.TextField()
nameLast = models.TextField()
nameGiven = models.TextField()
weight = models.IntegerField()
height = models.IntegerField()
bats = models.TextField()
throws = models.TextField()
debut = models.DateField()
finalGame = models.DateField()
retroID = models.TextField()
bbrefID = models.TextField()
Импортировать сценарий
import pandas as pd
from api.models import Person
people_csv = pd.read_csv('data/People.csv')
people_objects = []
for p in people_csv.iterrows():
person = Person()
person.playerID = p.playerID
person.birthYear = p.birthYear
person.birthMonth = p.birthMonth
person.birthDay = p.birthDay
person.birthCountry = p.birthCountry
person.birthState = p.birthState
person.birthCity = p.birthCity
person.deathYear = p.deathYear
person.deathMonth = p.deathMonth
person.deathDay = p.deathDay
person.deathCountry = p.deathCountry
person.deathState = p.deathState
person.deathCity = p.deathCity
person.nameFirst = p.nameFirst
person.nameLast = p.nameLast
person.nameGiven = p.nameGiven
person.weight = p.weight
person.height = p.height
person.bats = p.bats
person.throws = p.throws
person.debut = p.debut
person.finalGame = p.finalGame
person.retroID = p.retroID
person.bbrefID = p.bbrefID
people_objects.append(p)
Person.objects.bulk_create(people_objects)
Я предполагаю, что мне нужно добавить свой скрипт импорта где-нибудь в setting.py или каком-либо другом модуле.Я просто не на 100% уверен в , где и что мне нужно добавить.
Структура папки
![enter image description here](https://i.stack.imgur.com/0Q44g.png)