Pycharm error: Improperly configured

11,070

For Pycharm, just go to Run -> Edit Configurations, select your project on the right of the window from Debug Configuration, and you will see Environment variables on the right. Make sure you have set DJANGO_SETTINGS_MODULE=mysite.settings, if not just add one, it is as easy as fill a key value pair from the pop up dialog.

Share:
11,070
Rmartin
Author by

Rmartin

Updated on June 05, 2022

Comments

  • Rmartin
    Rmartin about 2 years

    After having an unexpected shutdown on my DEV machine, when going back to Pycharm project, I noticed the Django view file I was editing (which had 700+ lines) when that happened, it was completely empty. I managed to restore it from a backup; no loss there.

    The problem comes up when trying to debug, it returns this error: "ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings." Process finished with exit code 137

    The Pycharm settings Django Support (project root, settings & manage script) have the expected values as well.

    If I run the project with the ./manage .py runserver command, everything is fine. I can even access the DB with manage.py dbshell. I looked at my settings file and everything seems OK. I also updated from version 3.0.1 to 3.1.1, and no difference.

    I'm using Django 1.6.1 and postgresql 9.2.7. What can I do?

  • phouse512
    phouse512 about 8 years
    this should be the approved answer. I had a nightmare trying to figure out the pycharm config for unit tests, and this worked perfectly!
  • anonymous
    anonymous about 7 years
    If you are separating mysite/settings.py file into mysite/settings/production.py and mysite/settings/development.py, you could just set DJANGO_SETTINGS_MODULE=mysite.settings.development, for example.
  • physicalattraction
    physicalattraction almost 7 years
    This was the solution to my answer! I first forgot to inherit from Django's TestCase, and then run it as a test. PyCharm thought it was a Python test. After that, I added the inheritance, but the Run Configuration did not get updated by itself.