Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have Ubuntu 12.10 and have installed Django on it. I am trying to follow the tutorial on http://www.djangoproject.com. I am at the point where I run the python manage.py syncdb command. The below is the traceback.

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 288, in _cursor
    self._sqlite_create_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 257, in _sqlite_create_connection
    raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
django.core.exceptions.ImproperlyConfigured: Please fill out the database NAME in the settings module before using the database.

The following is an excerpt from my settings.py file:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3', 'sqlite3'# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': '',                      # Or path to database file if using sqlite3.
    'USER': '',                      # Not used with sqlite3.
   'PASSWORD': '',                  # Not used with sqlite3.
    'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
    'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
}
}

I did a lot of Googling and was told that for the NAME field, to put in the absolute path to the database file. What is the database file and where is it located? I know I have sqlite3. However, I cannot find any .db file anywhere. Another resource I looked at told me to just enter any path. When I do that, I get a Cannot open database error. Any help is greatly appreciated.

share|improve this question

1 Answer

up vote 4 down vote accepted

You need to provide django with where you'd like it to create the DB file - that location needs to be writable by the user that runs ./manage.py syncdb (you).

For instance, you could use:

'NAME': '~/my_test_db.db',

In development, it's common to use a location relative to your settings.pyfile:

from os import path

SETTINGS_ROOT = path.dirname(path.realpath(__file__)) # Folder where settings.py is
PROJECT_ROOT = path.normpath(path.join(SETTINGS_ROOT, '..')) # Django 1.4 project structure

...

    'NAME': path.join(PROJECT_ROOT, 'project.db'),

On a sidenote, there appears to be typo in your settings file:

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

should read:

'ENGINE': 'django.db.backends.sqlite3','
share|improve this answer
Thanks that worked! – noblerare Jan 9 at 17:10
@noblerare Glad it did : ) – Thomas Orozco Jan 9 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.