Django Db Settings 'Improperly Configured' Error

Django DB Settings 'Improperly Configured' Error

You can't just fire up Python and check things, Django doesn't know what project you want to work on. You have to do one of these things:

  • Use python manage.py shell
  • Use django-admin.py shell --settings=mysite.settings (or whatever settings module you use)
  • Set DJANGO_SETTINGS_MODULE environment variable in your OS to mysite.settings
  • (This is removed in Django 1.6) Use setup_environ in the python interpreter:

    from django.core.management import setup_environ
    from mysite import settings

    setup_environ(settings)

Naturally, the first way is the easiest.

settings.DATABASES is improperly configured” error django 3.1 while running inspect db

I got it working using the below command for inspect db

python manage.py inspectdb --database population_db population > model.py

Q: Django ImproperlyConfigured - from django.contrib.auth.models import User

If this is Django, and not flask as the vega_flask_run.py name implies then you need to run python manage.py runserver to start the application.

This might be a duplicate of Django ImproperlyConfigured for import User.

Also, models.py is not a script your run in django in the manner I think you're saying. It is where the models you define, the classes, for your project are located.

I may be the one missing something. Maybe you can edit your question with the vega_flask_run.py file. Perhaps you're using it in a way that I'm just not familiar with.

Otherwise, I suggest you start with https://docs.djangoproject.com/en/4.0/intro/tutorial01/. I mean it looks like you've already started the project correctly since you have the django files there. Maybe it's just a matter of how you start them.

Edit

Yes, now I can see that you're trying to run a djagno app as if it were a flask app, app = Flask(__name__, .... Despite both Flask and Django being python frameworks, they are run very differently.

Django - settings.DATABASES is improperly configured. Please supply the ENGINE value

Turns out I'm an idiot.

I'm using docker and I forgot that I need to enter the container to do DB migrations ‍♂️

The exact cause of this error is that the dockerfile creates an environment variable called "DJANGO_SETTINGS_MODULE" which Django looks for and the value is the name of an alternate file to be used for settings. As I wasn't in the docker container, this environment variable wasn't available so it was using the default settings.py which has had its DB settings removed.

How can I solve the ImproperlyConfigured error in Django

Seems you are just running python. You need to access shell as below.

python manage.py shell


Related Topics



Leave a reply



Submit