Answer the question
In order to leave comments, you need to log in
How to edit a database from another external file?
I want to add a couple of values to my database from a separate file
I tried to include models.py but I got an error
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Answer the question
In order to leave comments, you need to log in
Your best bet is to write a management command . Or to fence similar crutches in your script:
import django
from django.conf import settings
settings.configure(
DATABASES={
'default': {
'ENGINE': '<your_engine>',
'NAME': '<database_name>',
'HOST': '<hostname_or_ip>',
'PORT': '<port>',
'USER': '<user>',
'PASSWORD': '<super_secret_password>',
}
},
INSTALLED_APPS=[
'<your_app>',
]
)
django.setup()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question