python manage.py makemigrations

July 1, 2016 1.1k views
PostgreSQL Python Ubuntu 16.04

when migrate detabase

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/alam/myproject/myprojectenv/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/alam/myproject/myprojectenv/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 302, in execute
    settings.INSTALLED_APPS
  File "/home/alam/myproject/myprojectenv/local/lib/python3.5/site-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/home/alam/myproject/myprojectenv/local/lib/python3.5/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/alam/myproject/myprojectenv/local/lib/python3.5/site-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/alam/myproject/myprojectenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 658, in exec_module
  File "<frozen importlib._bootstrap_external>", line 764, in get_code
  File "<frozen importlib._bootstrap_external>", line 724, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/alam/myproject/myproject/settings.py", line 2
    Generated by 'django-admin startproject' using Django 1.9.7.
               ^
SyntaxError: invalid syntax
2 Answers

This error indicates that there is a problem in your settings file found at /home/alam/myproject/myproject/settings.py The key part of the message is:

  File "/home/alam/myproject/myproject/settings.py", line 2
    Generated by 'django-admin startproject' using Django 1.9.7.
               ^
SyntaxError: invalid syntax

When you create a new Django project, the boilerplate at the top of the settings file includes a comment like:

"""
Django settings for foo project.

Generated by 'django-admin startproject' using Django 1.9.7.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

In Python, putting three quotation marks (""") both above and below a block of text makes it a comment that is not evaluated as code. I suspect that you may have accidentally uncommented this text. Make sure it sure it is all commented out.

Have another answer? Share your knowledge.