Python Django抛出不正确的数据库配置错误

Python Django抛出不正确的数据库配置错误,python,django,database,configuration,Python,Django,Database,Configuration,所以我在早些时候发布了关于Django的一些问题,但这并没有得到解决。在那之后我改变了我的方法。这是我目前面临的问题。每当我尝试运行此脚本时,它都会抛出此错误 File "/usr/local/lib/python2.7/dist-packages/django/db/backends/dummy/base.py", line 21, in complain raise ImproperlyConfigured("settings.DATABASES is improperly con

所以我在早些时候发布了关于Django的一些问题,但这并没有得到解决。在那之后我改变了我的方法。这是我目前面临的问题。每当我尝试运行此脚本时,它都会抛出此错误

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/dummy/base.py", line 21, in complain
     raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
 django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
这似乎是在我将导入和导出数据库脚本的csv版本移动到主项目文件夹(而不是应用程序文件夹)之后发生的。这就是代码当前的样子

# exports db as a csv file

import sys, os
#sys.path.append(os.path.expanduser('~/Documents/swen261/masterProject/HealthNet'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'HealthNet.settings'
import django
from django.conf import settings
settings.configure()
django.setup()
print(sys.path)
from django.db import models
from main_site.models import *

print("Starting DB export script...\n")

print("Creating csv file 'csv_output.csv'...\n")
with open('csv_output.csv', 'w+') as file:
    print("Writing out Patients...\n")
for p in Patient.objects.all():
    file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,\n"
               % ("Patient", p.user.username, p.user.password, p.user.first_name, p.user.last_name, p.hospital.name, p.insurance_provider, p.insurance_id, "nil"))
print("Writing out Doctors...\n")
for d in Doctor.objects.all():
    file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,\n"
               % ("Doctor", d.user.username, d.user.password, d.user.first_name, d.user.last_name, d.hospital.name, "nil","nil","nil"))
print("Writing out Nurses...\n")
for n in Nurse.objects.all():
    file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,\n"
               % ("Nurse", n.user.username, n.user.password, n.user.first_name, n.user.last_name, n.hospital.name, "nil", "nil", "nil"))
print("Writing out Hospital Admins...\n")
for ha in HospitalAdmin.objects.all():
    file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,\n"
               % ("HospitalAdmin", ha.user.username, ha.user.password, ha.user.first_name, ha.user.last_name, ha.hospital.name, "nil", "nil", "nil"))

print("Finished creating csv.\n")
这是settings.py的相关部分

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
这是目录结构

有人知道如何阻止这种情况发生吗。脚本到达第一个Patient.objects.all(),然后抛出异常

from django.conf import settings
settings.configure()
使用默认设置(而不是应用程序设置)配置Django

解决方案1 解决方案2 删除以下行:

import django
from django.conf import settings
settings.configure()
django.setup()
Django使用
Django\u设置\u模块
变量进行自动配置

import django
from django.conf import settings
settings.configure()
django.setup()