0

I created a new app using python manage.py startapp associations I added it to installed apps but when I try to call the models inside management commands -fill_brands_table, I'm getting these error:

from associations.models import Brand ModuleNotFoundError: No module named 'associations'

settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'associations',
]

management command -fill_brands_table:

from django.core.management import BaseCommand
from associations.models import Brand #failed here

directory structure:

associations/
    management/
        commands/
             fill_brands_table.py
             __init__.py
        __init__.py
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py

 project/
     __init__.py
     settings.py
     urls.py
     wsgi.py
j.her
  • 187
  • 1
  • 2
  • 11
  • 4
    @user11418935 please only recommend that if it's actually relevant to the question. – Daniel Roseman Jul 31 '19 at 11:44
  • Add ```__init__.py``` both under management and commands directories. – cagrias Jul 31 '19 at 11:45
  • @cagrias still not working – j.her Jul 31 '19 at 11:48
  • `__init__` is not require if he\she is using python 3.3+ version. https://stackoverflow.com/questions/37139786/is-init-py-not-required-for-packages-in-python-3-3 – Harsha Biyani Jul 31 '19 at 11:48
  • Put an empty ```__init__.py``` under ```management``` as well. – cagrias Jul 31 '19 at 11:48
  • Where is that `associations` folder in relation to the rest of the project? – Daniel Roseman Jul 31 '19 at 11:49
  • 2
    How do you run your command? Did you try `python manage.py fill_brands_table`? And where is your working directory? – scriptboy Jul 31 '19 at 11:52
  • Where is your manage.py, I think it needs to be alongside your application and project folders? Like associations/, project/ and manage.py all in the same folder. And there's no need to have \_\_init\_\_ in your commands folder imo. And like scriptboy said, I hope you're running it with python manage.py fill_brands_table and not python fill_brands_table.py lol. – AbdurRehman Khan Jul 31 '19 at 11:54

0 Answers0