ImportError: cannot import name 'setup_environ'
I am creating models in django environment. Below is the sample code.
class Album(models.Model): artist = models.CharField(max_length=255) album_title = models.CharField(max_length=500) genre = models.CharField(max_length=255) logo = models.CharField(max_length=1000) def __str__(self): return self.album_title + ': ' + self.artist class Song(models.Model): artist = models.ForeignKey(Album, on_delete=models.CASCADE, null = True) file_type = models.CharField(max_length=255) song_title = models.CharField(max_length=255) def __str__(self): return self.song_title
I was getting below 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.
So, I got some article that suggested me to import django module
from django.core.management import setup_environ import settings setup_environ(settings)
So now, the above error was corrected, but I got new error as below
File "<ipython-input-8-3168a50cefba>", line 2, in <module> from django.core.management import setup_environ ImportError: cannot import name 'setup_environ'
I know that the django module is present in my IDE, coz, when I hovered my cursor on the warning icon near the django module it said "django imported but not used". But that is not our concern, as I happened to get rid of the warning.
Spyder IDE - 3.2.3 Python - 3.6 Django - 1.11.3-py36_0
mport os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Test_Django_project.settings") try: from django.core.management import execute_from_command_line except ImportError: # The above import may fail for some other reason. Ensure that the # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: import django except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) raise execute_from_command_line(sys.argv)