Reputation: 695
So I posted earlier about some problems with Django, but that wasn't able to be solved. I changed my approach after that. Here is the problem that I am currently facing. Whenever I try to run this script it throws this error...
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.
This seems to be happening after I moved my import and export a csv version of the db scripts to the main project folder as opposed to an app folder. This is what the code currently looks like...
# 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")
This is the pertinent section of 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'),
}
}
And this is the directory structure...
Does anyone have any idea as to how to stop that from happening. The script reaches the first Patient.objects.all(), and then throws the exception.
Upvotes: 1
Views: 461
Reputation: 10680
from django.conf import settings
settings.configure()
configure Django with default settings (not Your app settings).
from HealthNet import settings as my_settings
from django.conf import settings
settings.configure(default_settings=my_settings)
Remove following lines:
import django
from django.conf import settings
settings.configure()
django.setup()
Django uses autoconfigure using DJANGO_SETTINGS_MODULE
variable.
Upvotes: 2