Django/Python feeding back ImproperlyConfigured for makemigrations for AppConfiguring

381 views Asked by At

Following along a tutorial and I have been able to solve all my little issues so far until I get to my back-end creating my own 'app' for data I can lookup with SQlite.

My work flow:

> DJANGO-WEBSITE:
> capstone_project_website:
>     settings.py 
>     apps:
>         accounts:
>             models.py 
>             apps.py 
> requirements:
> scripts:
> manage.py

my /mymodels.py:

from django.db import models
from django.contrib.auth.models import User

class UserInterest(models.Model):
    # name of interest
    name = models.CharField(max_length=64, unique=True)
    normalized_name = models.CharField(max_length=64, unique=True)

    # string function to print the name
    def __str__(self):
        return self.name

class UserPersona(models.Model):
    name = models.CharField(max_length=64, unique=True)
    normalized_name = models.CharField(max_length=64, unique=True)
    description = models.CharField(max_length=200)

    def __str__(self):
        return self.name


# Create your models here
class UserProfile(models.Model):
    # Owner. Foreign key. Whenever we fetch user, we should fetch the user profile
    # related_name = we can access profile through user object aka request.user.profile
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")

    # settings
    is_full_name_displayed = models.BooleanField(default=True)

    # details
    bio = models.CharField(max_length=500, default=True, null=True)
    website = models.URLField(max_length=500, default=True, null=True)
    persona = models.ForeignKey(UserPersona, on_delete=models.SET_NULL, blank=True, null=True)
    interests = models.ManyToManyField(UserInterest, blank=True)

my /settings.py:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "capstone_project_website.apps.accounts",
]

my /apps.py

from django.apps import AppConfig


class AccountsConfig(AppConfig):
    
    name = "accounts"

the error on my terminal that shows up after running python manage.py makemigrations is:

python manage.py makemigrations

Traceback (most recent call last):
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/apps/config.py", line 244, in create
    app_module = import_module(app_name)
  File "/Users/ryandeaver/opt/anaconda3/envs/3.7.3/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'accounts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ryandeaver/Desktop/django-website/manage.py", line 22, in <module>
    main()
  File "/Users/ryandeaver/Desktop/django-website/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "/Users/ryandeaver/.pyenv/versions/[email protected]/lib/python3.9/site-packages/django/apps/config.py", line 246, in create
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Cannot import 'accounts'. Check that 'capstone_project_website.apps.accounts.apps.AccountsConfig.name' is correct.

In advance thank you for any help!

1

There are 1 answers

1
harceo On

In apps.py change name = capstone_project_website.apps.accounts and in your settings in your installed apps use 'capstone_project_website.apps.AccountsConfig'