Hi. I have just started building my first django app and am currently stuck at the part where I’m supposed to be executing a python manage.py makemigrations
Upon executing the ‘python manage.py makemigrations’ command in the terminal, I received this error:
(venv) PS C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard> Python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Program Files\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard\main\models.py", line 5, in <module>
from .utilities import send_activation_notification
ModuleNotFoundError: No module named 'main.utilities'
This is my settings.py file.
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-7n1pyfqd2&#)3%=2-2@hqpqpak#itpw4mlp5&*+gk3xb6okda%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig',
'bootstrap4',
]
AUTH_USER_MODEL = 'main.AdvUser'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'bboard.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'bboard.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'bboard.data',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'ru-r'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'username@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
This is my apps.py file:
from django.apps import AppConfig
class MainConfig(AppConfig):
verbose_name = 'Электронная доска объявлений'
name = 'main'
This is my models.py file:
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.dispatch import Signal
from .utilities import send_activation_notification
class AdvUser(AbstractUser):
is_activated = models.BooleanField(default=True, db_index=True,
verbose_name='Прошел активацию?')
send_messages = models.BooleanField(default=True,
verbose_name='Оповещать при новых комментариях?')
class Meta(AbstractUser.Meta):
pass
user_registrated = Signal(providing_args=['instance'])
def user_registrated_dispatcher(sender, **kwargs):
send_activation_notification(kwargs['instance'])
user_registrated.connect(user_registrated_dispatcher)
class AdvUser(AbstractUser):
is_activated = models.BooleanField(default=True, db_index=True,
verbose_name='Прошел активацию?')
send_messages = models.BooleanField(default=True,
verbose_name='Оповещать при новых комментариях?')
class Meta(AbstractUser.Meta):
pass
class Rubric(models.Model):
name = models.CharField(max_length=20, db_index=True, unique=True,
verbose_name='Название')
order = models.SmallIntegerField(default=0, db_index=True,
verbose_name='Порядок')
super_rubric = models.ForeignKey('SuperRubric',
on_delete=models.PROTECT, null=True, blank=True,
verbose_name='Надрубрика')
class SuperRubricManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(super_rubric__isnull=True)
class SuperRubric(Rubric):
object = SuperRubricManager()
def __str__(self):
return self.name
class Meta:
proxy = True
ordering = ('order', 'name')
verbose_name = 'Надрубрика'
verbose_name_plural = 'Надрубрики'
class SubRubricManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(super_rubric__isnull=False)
class SubRubric(Rubric):
object = SubRubricManager()
def __str__(self):
return '%s - %s' % (self.super_rubric, self.name)
class Meta:
proxy = True
ordering = ('super_rubric__order', 'super_rubric__name', 'order', 'name')
verbose_name = 'Подрубрика'
verbose_name_plural = 'Подрубрики'
Django version - 3.2.16
Python version - 3.7.2
Pip version - 21.3.1
I have also included a screenshot of my settings.py file in case there is some info I forgot to mention. The entire directory is visible in the image.
I suspect the problem may be due to the placement of my file directories. Any advice?