Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Django Templates Templates

Cannot run manage.py file

Hello Try to run the server with virtual venv The terminal report error that:

(base) OSX-MacBook-Pro:learning_site osx$ source mysitevenv/bin/activate
(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ python3 manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_lineModuleNotFoundError: No module named 'django'
(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ pwd
/Users/osx/Downloads/Django Basics 2/s5v1/learning_site(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ ls
assets          learning_site   mysitevenv
courses         manage.py       templates(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ python -m pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ python mange.py runserver
/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Pytho
n: can't open file 'mange.py': [Errno 2] No such file or directory
(mysitevenv) (base) OSX-MacBook-Pro:learning_site osx$ python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line
 926, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line
 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/si
te-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
    raise _exception[1]
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/mysitevenv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/courses/models.py", line 13, in <module>
    class Step(models.Model):
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/courses/models.py", line 17, in Step
    course = models.ForeignKey(Course)
TypeError: __init__() missing 1 required positional argument: 'on_delete'

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

The last few lines point to the error:

File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/courses/models.py", line 13, in <module>
    class Step(models.Model):
  File "/Users/osx/Downloads/Django Basics 2/s5v1/learning_site/courses/models.py", line 17, in Step
    course = models.ForeignKey(Course)
TypeError: __init__() missing 1 required positional argument: 'on_delete'

In models.py, the class Step uses a ForeignKey reference without the required argument ’on_delete’

Post back if you need more help. Good luck!!!