Django Tutorial(Database Setup Question)

69 views
Skip to first unread message

Cai Gengyang

unread,
Sep 27, 2015, 6:50:47 AM9/27/15
to Django users

Hello all !

So I am going through the (Database setup) chapter of this tutorial (https://docs.djangoproject.com/en/1.8/intro/tutorial01/) --- Its the section right after the first chapter on "Creating a project"


I opened up mysite/settings.py as per the instructions on the Django tutorial.


However, when I try to run the following command : $ python manage.py migrate to create the tables in the database,


CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- input


I get the following error message :


/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory ---- output


Any idea how to solve this issue?


Thanks a lot !


Gengyang


Tom Lockhart

unread,
Sep 27, 2015, 7:12:54 AM9/27/15
to django...@googlegroups.com
> …
> However, when I try to run the following command : $ python manage.py migrate to create the tables in the database,
> CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- input
> I get the following error message :
> /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory ---- output

You need to be in the same directory as the file manage.py for the command to work. For Django-1.8 that is likely to be one level above your settings.py file.

hth

- Tom

Cai Gengyang

unread,
Sep 27, 2015, 7:39:11 AM9/27/15
to Django users
Hi Tom,


So I click on Finder ---> Go ---> Home ---> 'Weiqi' folder ---> mysite folder ---> manage.py file. (using a Mac OS X Yosemite Version 10.10.2)

This puts me in the same directory as the manage.py file.

Then I key in the command  : $ python manage.py migrate, but I still get the same error message 

CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate --- input


/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory --- output 


Not sure where I am doing this wrongly ... zzz



Gengyang

Tom Lockhart

unread,
Sep 27, 2015, 7:51:51 AM9/27/15
to django...@googlegroups.com

> On Sep 27, 2015, at 04:39, Cai Gengyang <gengy...@gmail.com> wrote:
>
> Hi Tom,
> So I click on Finder ---> Go ---> Home ---> 'Weiqi' folder ---> mysite folder ---> manage.py file. (using a Mac OS X Yosemite Version 10.10.2)
> This puts me in the same directory as the manage.py file.
> Then I key in the command : $ python manage.py migrate

The command must be typed from a terminal window, and afaik Finder has no influence on the current working directory in that window.

Use the Terminal app to open a command line window, then use “cd” or “pushd” to go to “mysite folder” within that terminal window.

If that is done correctly, then you should be able to type “ls” and see manage.py in the resulting listing. Then try typing the python command above.

btw, I would strongly recommend using virtualenv for developing on your Mac (and on any other system). There are many references to that in this mailing list; do a google search to find a procedure for doing this.

hth

- Tom

Cai Gengyang

unread,
Sep 27, 2015, 8:26:04 AM9/27/15
to Django users
Hi Tom,

Following your latest instructions , I have posted my input and output results here. Still getting an error message though it is a different one this time ( a traceback error )

CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls

manage.py mysite

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate

Traceback (most recent call last):

  File "manage.py", line 10, in <module>

    execute_from_command_line(sys.argv)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line

    utility.execute()

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute

    settings.INSTALLED_APPS

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__

    self._setup(name)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup

    self._wrapped = Settings(settings_module)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__

    mod = importlib.import_module(self.SETTINGS_MODULE)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module

    __import__(name)

  File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45

    'django.middleware.csrf.CsrfViewMiddleware',

                                              ^

SyntaxError: invalid syntax

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ 

Tom Lockhart

unread,
Sep 27, 2015, 8:34:35 AM9/27/15
to django...@googlegroups.com
On Sep 27, 2015, at 05:26, Cai Gengyang <gengy...@gmail.com> wrote:

Hi Tom,

Following your latest instructions , I have posted my input and output results here. Still getting an error message though it is a different one this time ( a traceback error )

Oh, much better :)

You are now seeing a typo in your settings.py file. Without seeing more of the file I can not guess at the exact place with the error, but perhaps you have an extra or a missing single quote character in a preceeding line in the file??

hth

- Tom


-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/278af114-1a2e-4c4b-ab90-f2c4814d7f4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gergely Polonkai

unread,
Sep 27, 2015, 8:35:21 AM9/27/15
to Django users

Hello,

that message is clear: line 45 in your settings.py has a syntax error. That line, however, seem OK, so I guess the previous one is that; maybe a comma is missing.

Best,
Gergely

--

Cai Gengyang

unread,
Sep 27, 2015, 9:04:09 AM9/27/15
to Django users

This is my entire settings.py file


"""

Django settings for mysite project.


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


For more information on this file, see

https://docs.djangoproject.com/en/1.8/topics/settings/


For the full list of settings and their values, see

https://docs.djangoproject.com/en/1.8/ref/settings/

"""


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/


# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = '6d9q_36l6ka7pkt=e1-r*ze_!tx0bst1i1^!6khpn19yj20^sg'


# 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',

)


MIDDLEWARE_CLASSES = (

    'django.contrib.sessions.middleware.SessionMiddleware',

    'django.middleware.common.CommonMiddleware',

    'django.middleware.csrf.CsrfViewMiddleware',

    'django.contrib.auth.middleware.AuthenticationMiddleware',

    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',

    'django.contrib.messages.middleware.MessageMiddleware',

    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'django.middleware.security.SecurityMiddleware',

)


ROOT_URLCONF = 'mysite.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 = 'mysite.wsgi.application'



# Database

# https://docs.djangoproject.com/en/1.8/ref/settings/#databases


DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

    }

}



# Internationalization

# https://docs.djangoproject.com/en/1.8/topics/i18n/


LANGUAGE_CODE = 'en-us'


TIME_ZONE = 'UTC'


USE_I18N = True


USE_L10N = True


USE_TZ = True



# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/1.8/howto/static-files/


STATIC_URL = '/static/'

Tom Lockhart

unread,
Sep 28, 2015, 1:50:18 AM9/28/15
to django...@googlegroups.com
On Sep 27, 2015, at 06:04, Cai Gengyang <gengy...@gmail.com> wrote:

This is my entire settings.py file


I’m not seeing the problem, but it is certainly there somewhere.

Try removing pieces of the settings file until you can isolate the syntax problem which is likely on or before line 45. Copy the original one aside so you can go back to it and repair the problem once you figure out where it is.

hth

- Tom

Cai Gengyang

unread,
Sep 28, 2015, 2:17:02 AM9/28/15
to Django users

Hey guys, I am happy to announce that it finally works. The problem was that there was an additional 'qq' in my settings.py file on line 44.(no idea how it got there) I have posted my entire input / output here for viewing and discussion ...



CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls

manage.py mysite

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate

Operations to perform:

  Synchronize unmigrated apps: staticfiles, messages

  Apply all migrations: admin, contenttypes, auth, sessions

Synchronizing apps without migrations:

  Creating tables...

    Running deferred SQL...

  Installing custom SQL...

Running migrations:

  Rendering model states... DONE

  Applying contenttypes.0001_initial... OK

  Applying auth.0001_initial... OK

  Applying admin.0001_initial... OK

  Applying contenttypes.0002_remove_content_type_name... OK

  Applying auth.0002_alter_permission_name_max_length... OK

  Applying auth.0003_alter_user_email_max_length... OK

  Applying auth.0004_alter_user_username_opts... OK

  Applying auth.0005_alter_user_last_login_null... OK

  Applying auth.0006_require_contenttypes_0002... OK

  Applying sessions.0001_initial... OK

CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ 

Reply all
Reply to author
Forward
0 new messages