django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment varia

前端 未结 8 1845
遇见更好的自我
遇见更好的自我 2020-12-28 14:46

I\'ve tried everything that I could find to fix this issue, and I\'m starting to tear my hair out a little. I\'m getting this error:

django.core.exceptions.I         


        
相关标签:
8条回答
  • 2020-12-28 14:54

    I got this error when I imported TestCase from unittest2. I fixed it by importing TestCase by:

    from django.test import TestCase
    

    My suspicions were raised when the test was labelled "Unittest" rather than "Test". I had to run the whole suite before Pycharm realised I'd made this change...

    0 讨论(0)
  • 2020-12-28 14:57

    fill "working directory" correctly with your working path then write the copy down in it's place

    0 讨论(0)
  • 2020-12-28 15:04

    In my case I needed to use

    python3 manage.py check --deploy
    

    instead of

    django-admin check --deploy
    
    0 讨论(0)
  • 2020-12-28 15:07

    since, I don't want to add this in every file, I created a file called usercustomize.py and added this content:

    import os
    os.environ['DJANGO_SETTINGS_MODULE']='foosite.settings'
    

    The file path in my case:

    src/foosite/usercustomize.py
    

    I installed foosite with "pip install -e". I am unsure if this works for normal installs.

    0 讨论(0)
  • 2020-12-28 15:13

    Use this

    import os
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
    

    instead of

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<appname>.settings")
    
    0 讨论(0)
  • 2020-12-28 15:16

    If you are using PyCharm Pro, you can either test your app by action 'Run Django Console...'. After you click 'test', it will prompt you for the app you want to test.

    enter image description here

    or

    Create a Django test in Run/Debug configuration.

    enter image description here

    0 讨论(0)
提交回复
热议问题