Using PyCharm Communuty: trying to run my PyCharm console with folowing code to do some tests but unfortunately facing the problem described below. Really appreciate your attention
from django.db import models
# Create your models here.
class ProductCategory(models.Model):
name = models.CharField(max_length=128, unique=True)
description = models.TextField(null=True, blank=True)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=256)
description = models.TextField()
price = models.DecimalField(max_digits=6, decimal_places=2)
quantity = models.PositiveIntegerField(default=0)
image = models.ImageField(upload_to='products_images')
category = models.ForeignKey(to=ProductCategory, on_delete=models.CASCADE)
Then trying to run PyCharm console and execute the folowing line:
from products.models import ProductCategory
Then getting error:
Traceback (most recent call last):
File "/snap/pycharm-community/310/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
File "<input>", line 1, in <module>
File "/snap/pycharm-community/310/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/verts/Documents/Last/course/store-server/store/products/models.py", line 5, in <module>
class ProductCategory(models.Model):
File "/home/verts/Documents/Last/course/store-server/store/venv/lib/python3.9/site-packages/django/db/models/base.py", line 108, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/verts/Documents/Last/course/store-server/store/venv/lib/python3.9/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
self.check_apps_ready()
File "/home/verts/Documents/Last/course/store-server/store/venv/lib/python3.9/site-packages/django/apps/registry.py", line 135, in check_apps_ready
settings.INSTALLED_APPS
File "/home/verts/Documents/Last/course/store-server/store/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
self._setup(name)
File "/home/verts/Documents/Last/course/store-server/store/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 63, in _setup
raise ImproperlyConfigured(
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.
App 'products' is registered in settings .. :(