0
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "D:\PythonPack\lib\site-packages\django\core\management\__init__.py", lin
e 443, in execute_from_command_line
    utility.execute()
  File "D:\PythonPack\lib\site-packages\django\core\management\__init__.py", lin
e 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 19
6, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 23
2, in execute
    output = self.handle(*args, **options)
  File "D:\PythonPack\lib\site-packages\django\core\management\base.py", line 30
4, in handle
    app_output = self.handle_app(app, **options)
  File "D:\PythonPack\lib\site-packages\django\core\management\commands\sqlall.p
y", line 19, in handle_app
    return u'\n'.join(sql_all(app, self.style, connections[options.get('database
')])).encode('utf-8')
  File "D:\PythonPack\lib\site-packages\django\core\management\sql.py", line 145
, in sql_all
    return sql_create(app, style, connection) + sql_custom(app, style, connectio
n) + sql_indexes(app, style, connection)
  File "D:\PythonPack\lib\site-packages\django\core\management\sql.py", line 26,
 in sql_create
    tables = connection.introspection.table_names()
  File "D:\PythonPack\lib\site-packages\django\db\backends\__init__.py", line 89
5, in table_names
    cursor = self.connection.cursor()
  File "D:\PythonPack\lib\site-packages\django\db\backends\__init__.py", line 30
6, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "D:\PythonPack\lib\site-packages\django\db\backends\sqlite3\base.py", lin
e 281, in _cursor
    self._sqlite_create_connection()
  File "D:\PythonPack\lib\site-packages\django\db\backends\sqlite3\base.py", lin
e 271, in _sqlite_create_connection
    self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file

I follow this tutorial https://docs.djangoproject.com/en/dev/intro/tutorial01/ and I run into the above errors when trying to execute the command

python manage.py sql polls

Anyone knows what might be the problem ? Thank you a lot.

ANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'E:\Python\mysite\sqlitedb', # 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.
    }
}



INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'polls',
)
1
  • Update the question with your your settings.py file. Commented Jun 24, 2012 at 13:38

1 Answer 1

2

Sqlite3 requires a full path to the database file. Make sure your database name is not a relative path.

Should be something like this:

import os
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite',
        'NAME': os.path.join(PROJECT_ROOT, 'dev.db'),
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

Also make sure the file doesn't have too strict permissions.

Sign up to request clarification or add additional context in comments.

2 Comments

Better than that I was going to write. Edited to add import line
Thank you Yuval I follow the tutorial to create a model file and run python manage.py sql polls which will create the db file for me, I think. so I don't need to specify the path to the db file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.